I have checked the docs of Dropbox API which had the following code:
curl -X POST https://api.dropboxapi.com/2/files/list_folder \
--header "Authorization: Bearer " \
--header "Content-Type: application/json" \
--data "{\"path\": \"/Homework/math\",\"recursive\": false,\"include_media_info\": false,\"include_deleted\": false,\"include_has_explicit_shared_members\": false,\"include_mounted_folders\": true,\"include_non_downloadable_files\": true}"
But how am I to use this code in PHP. I know how to use the header thing. Its like this
$headers = array(
'Authorization: Bearer 0tXsy9OsJNEAAAAAAAAAAThz0u5GSonbXXN2EwAe6Folfoeus643iyWWGQ6UcrF7',
'Content-Type: application/json')
But how to use the data part. When i input it like "Data" : ..... , then it gives me this error " Error in call to API function "files/list_folder": request body: could not decode input as JSON". What should I do?
CodePudding user response:
You can use something like this:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.dropboxapi.com/2/files/list_folder');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"path\": \"/Homework/math\",\"recursive\": false,\"include_media_info\": false,\"include_deleted\": false,\"include_has_explicit_shared_members\": false,\"include_mounted_folders\": true,\"include_non_downloadable_files\": true}");
$headers = array();
$headers[] = 'Authorization: Bearer';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);