如何在 PHP 中列出 Dropbox 中的文件名
How to list out file names from dropbox in PHP
我查看了 Dropbox API 的文档,其中包含以下代码:
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}"
但我如何在 PHP 中使用此代码。我知道如何使用 header 东西。是这样的
$headers = array(
'Authorization: Bearer <ACCESS_TOKEN>',
'Content-Type: application/json')
但是数据部分怎么用。当我像“数据”这样输入时:......,然后它给了我这个错误“调用API函数时出错“files/list_folder”:请求body:无法解码输入为 JSON”。我该怎么办?
你可以这样使用:
$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);
我查看了 Dropbox API 的文档,其中包含以下代码:
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}"
但我如何在 PHP 中使用此代码。我知道如何使用 header 东西。是这样的
$headers = array(
'Authorization: Bearer <ACCESS_TOKEN>',
'Content-Type: application/json')
但是数据部分怎么用。当我像“数据”这样输入时:......,然后它给了我这个错误“调用API函数时出错“files/list_folder”:请求body:无法解码输入为 JSON”。我该怎么办?
你可以这样使用:
$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);