You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

steve_lae0901's avatar
steve_lae0901
Helpful | Level 6
7 years ago

PHP file download returns page not found

using cURL in PHP to call the /files/download api.  Dropbox returns "Error (4xx) We can't find the page you're looking for."  How to troubleshoot? I think I am using the API correctly.

 

function getTextFile( $token )
{
  $ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, "https://content.dropboxapi.com/2/files/download");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0 ) ;

  $headers = array();
  $headers[] = "Authorization: Bearer " . $token ;
  $headers[] = "Dropbox-Api-Arg: {\"path\": \"/test_upload.txt\"}";
  $headers[] = 'Content-Type: text/plain; charset=utf-8' ;
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

  $result = curl_exec($ch);
  if (curl_errno($ch)) {
      echo 'Error:' . curl_error($ch);
  }
  curl_close ($ch);
  return $result ;
}

 

 

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff
    I don't see anything clearly wrong here. (We recommend not disabling SSL verification though.)

    Anyway, it's possible to get that generic 4xx error if the HTTP request itself is malformed. For example, perhaps $token is leaking an invalid value into the Authorization header. Can you check that it is the access token string only?
    • steve_lae0901's avatar
      steve_lae0901
      Helpful | Level 6

      Thanks for the help Greg.

       

      I run this code on a PHP hosting site and it works. Run it on our production ZEND PHP server and it fails.    So I do not know what to do.  For now I am going to have the hosting site get the files from dropbox. Then use cURL to send the data from the hosting site  to the production server.


      I ran the code with CURLOPT_HEADERFUNCTION.  Got this back:

      HTTP/1.1 400 Bad Request 
      Server: nginx 
      Date: Thu, 08 Feb 2018 22:26:12 GMT 
      Content-Type: text/html 
      Content-Length: 25658 
      Connection: close 
      ETag: "5a0b785f-643a" 
      X-Dropbox-Request-Id: 0acd4bd5e915ad747d40dfaff467b9ca 
      X-Robots-Tag: noindex, nofollow, noimageindex 
       
       
  • steve_lae0901's avatar
    steve_lae0901
    Helpful | Level 6

    this PHP code works on a server running PHP 7.0.27.  It is failing on PHP 5.6.15.

     

    • Greg-DB's avatar
      Greg-DB
      Icon for Dropbox Staff rankDropbox Staff
      The output you shared is from the response. Can you inspect the request itself?

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,911 PostsLatest Activity: 10 hours ago
333 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!