cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

error using PHP file_get_contents to call list_folder api

error using PHP file_get_contents to call list_folder api

steve_lae0901
Helpful | Level 6
Go to solution

any examples available using the PHP file_get_contents function to call the files/list_folder api? 

( I am able to use curl from PHP to call the dropbox apis. But my code fails on one PHP server but works on another. Would like to see if file_get_contents will work. )

 

Here is my code.  There error I am getting is "failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request "


function listFolder( $token )
{
  $text = "{\"path\": \"\",\"recursive\": false,\"include_media_info\": false,\"include_deleted\": false,\"include_has_explicit_shared_members\": false,\"include_mounted_folders\": true}" ;
  echo $text . '<br>' ;

  $postdata = http_build_query(
    array(
        'data' => $text)) ;

  $opts = array(
      'http' => array(
                'method'  => 'POST',
                'header'  => array('Authorization: Bearer ' . $token,
                                   'Content-Type: application/json'),
                'content' => $postdata),
      'ssl' => array(
                "verify_peer"=>false,
                "verify_peer_name"=>false)
  );

  $context  = stream_context_create($opts);

  $result = file_get_contents('https://api.dropboxapi.com/2/files/list_folder', false, $context);
}

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

I don't believe we have an example for using file_get_contents.

In any case, when you get an error from the API, such as a 400 response, the best first step is to check the response body, which should contain a more useful error.

Anyway, it looks like you have a newer thread, so I'll follow up there:

https://www.dropboxforum.com/t5/API-support/PHP-file-download-returns-page-not-found/m-p/264177#M154...

View solution in original post

1 Reply 1

Greg-DB
Dropbox Staff
Go to solution

I don't believe we have an example for using file_get_contents.

In any case, when you get an error from the API, such as a 400 response, the best first step is to check the response body, which should contain a more useful error.

Anyway, it looks like you have a newer thread, so I'll follow up there:

https://www.dropboxforum.com/t5/API-support/PHP-file-download-returns-page-not-found/m-p/264177#M154...

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?