如何预览 Dropbox 文件夹中的文件
How to preview the files from Dropbox folder
我在 Dropbox 帐户的文件夹中添加了一些文件。在每个文件旁边我都放了一个下载按钮来显示 Dropbox 文件夹中的文件。
我已经尝试在 Dropbox API 中设置共享链接,但它只能使用一次。如果我第二次点击它,它说共享链接已经存在。
有没有其他方法可以将 Dropbox 文件夹中的文件预览到我们的页面?
下面是共享链接的代码:
$path='/test.txt';
$ch = curl_init();
$url1="https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings";
$post = array(
"path"=> "/".$path,
"settings"=> array(
"requested_visibility"=> "public"
)
);
$link = json_encode($post);
curl_setopt($ch,CURLOPT_URL,$url1);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$link);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Content-Type: application/json';
$headers[] = "Authorization: Bearer ".$TOKEN;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response1 = curl_exec($ch);
$sharelink = json_decode($response1,true);
/2/sharing/create_shared_link_with_settings endpoint is expected to return shared_link_already_exists
if a link already exists. You can use /2/sharing/list_shared_links 检索现有的 link。
或者,您可以使用 /2/files/get_temporary_link 临时直接 link 到文件。
或者,对于支持的文件类型,您可以使用 /2/files/get_preview 来预览文件数据。
我在 Dropbox 帐户的文件夹中添加了一些文件。在每个文件旁边我都放了一个下载按钮来显示 Dropbox 文件夹中的文件。
我已经尝试在 Dropbox API 中设置共享链接,但它只能使用一次。如果我第二次点击它,它说共享链接已经存在。
有没有其他方法可以将 Dropbox 文件夹中的文件预览到我们的页面?
下面是共享链接的代码:
$path='/test.txt';
$ch = curl_init();
$url1="https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings";
$post = array(
"path"=> "/".$path,
"settings"=> array(
"requested_visibility"=> "public"
)
);
$link = json_encode($post);
curl_setopt($ch,CURLOPT_URL,$url1);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$link);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Content-Type: application/json';
$headers[] = "Authorization: Bearer ".$TOKEN;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response1 = curl_exec($ch);
$sharelink = json_decode($response1,true);
/2/sharing/create_shared_link_with_settings endpoint is expected to return shared_link_already_exists
if a link already exists. You can use /2/sharing/list_shared_links 检索现有的 link。
或者,您可以使用 /2/files/get_temporary_link 临时直接 link 到文件。
或者,对于支持的文件类型,您可以使用 /2/files/get_preview 来预览文件数据。