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
Squer
7 years agoExplorer | Level 4
API v2 with PHP
Hello I'am trying to do a very simple thing with no result. I just try to use the V2 API with PHP cURL. Nb I a m very new on the subject... According to the documentation I expect to receive the li...
- 7 years ago
1) It looks like there are two issues with this one:
a) You should be supplying the API call parameters as JSON in the body. So, instead of:
$curl_fields = http_build_query($fields); curl_setopt($ch, CURLOPT_POSTFIELDS,$curl_fields);
You would do something like:
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($fields));
b) When identifying just the root folder, you need to just use the empty string "", so instead of:
"path"=> "/",
Do:
"path"=> "",
2) I'm just running this code in my terminal. I can't offer help on your development environment itself, so you'll need to investigate how to properly get the error output in your environment. For reference, the Dropbox API returns error information in the response body, which both the `var_dump($result);` and `print_r($result);` in your code are showing me.
Squer
Explorer | Level 4
Hello
First thing, thanks a lot for your answer.
I've tried with 2/files/listfolder but unfortunately I got the same result (var_dump = false)
$ch = curl_init();
$fields =array(
"path"=> "/",
"recursive"=> false,
"include_media_info"=> false,
"include_deleted"=> false,
"include_has_explicit_shared_members"=> false,
"include_mounted_folders"=> true) ;
$curl_fields = http_build_query($fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $auth_token, 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS,$curl_fields);
try{
$result = curl_exec($ch);
} catch (Exception $e) {
echo 'Exception : ', $e->getMessage(), "\n";
}
var_dump($result);
print_r($result);
$array = json_decode(trim($result), TRUE);
print_r($array);
curl_close($ch);
1) Do you have a idea on what's wrong with my code?
2) How do you get the error message request "body: could not decode input as JSON" ? I do not receive any message unless I test in https://resttesttest.com/ (which doesn t work neither..)
Greg-DB
7 years agoDropbox Staff
1) It looks like there are two issues with this one:
a) You should be supplying the API call parameters as JSON in the body. So, instead of:
$curl_fields = http_build_query($fields); curl_setopt($ch, CURLOPT_POSTFIELDS,$curl_fields);
You would do something like:
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($fields));
b) When identifying just the root folder, you need to just use the empty string "", so instead of:
"path"=> "/",
Do:
"path"=> "",
2) I'm just running this code in my terminal. I can't offer help on your development environment itself, so you'll need to investigate how to properly get the error output in your environment. For reference, the Dropbox API returns error information in the response body, which both the `var_dump($result);` and `print_r($result);` in your code are showing me.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,915 PostsLatest Activity: 16 hours agoIf 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!