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

error using PHP file_get_contents to call list_folder api

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);
}

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,910 PostsLatest Activity: 4 days 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!