从保管箱下载文件到服务器

Download file from dropbox to the server

我想从 Dropbox 下载文件并需要代表 Dropbox 用户将其保存在我的服务器中。我尝试使用 curl 和 file_get_contents。但无法成功。我是否需要使用 dropbox 的任何 api 方法?我可以从浏览器下载文件,但我需要将它保存在服务器中。我的应用是一种文件共享。

Dropbox 浏览器客户端仅供注册用户使用,用户需要登录后才能访问其中的文件。

但是正如您所说,您想要访问 Dropbox 文件,代表用户,您需要使用 Dropbox 核心 API,您可以使用 PHP Dropbox SDK 构建您自己的应用程序。 我觉得没有别的办法了。

正如您所提到的,您想代表用户从 Dropbox 访问文件,我想您可能会在没有用户交互的情况下考虑它,但它有一个问题,Dropbox 使用 OAuth 1.0 or 2.0, and in both the methods, you need to have user interaction. ()

你也说了,你的应用是一种File Sharing,所以请看一看Dropbox App Review Process,它禁止公开搜索File Share应用。

Don't build file sharing apps

Dropbox doesn't support building publicly searchable file sharing networks on top of Dropbox.

您可以使用 Dropbox public link 到文件并使用 file_get_contentsfile_put_contents。 下面的香草 PHP 示例。

<?php
    // Custom Dropbox link. Notice the ?dl=1 at the end. 
    $url = file_get_contents( 'https://www.dropbox.com/s/hash/file.mp4?dl=1' );

    // Your new file name 
    $file = "downloaded-video.mp4";

    // open, write and close the new file
    file_put_contents($file, $url);
?>
来自服务提供商的

API 通常是访问其数据的最佳方式。这种方法肯定更好

我唯一的注意事项是:小心不要违反 Dropbox 的服务条款。

您可以使用/下载。它将 return 响应如下:

{
"name": "Prime_Numbers.txt",
"id": "id:a4ayc_80_OEAAAAAAAAAXw",
"client_modified": "2015-05-12T15:50:38Z",
"server_modified": "2015-05-12T15:50:38Z",
"rev": "a1c10ce0dd78",
"size": 7212,
"path_lower": "/homework/math/prime_numbers.txt",
"path_display": "/Homework/math/Prime_Numbers.txt",
"sharing_info": {
    "read_only": true,
    "parent_shared_folder_id": "84528192421",
    "modified_by": "dbid:AAH4f99T0taONIb-OurWxbNQ6ywGRopQngc"
},
"property_groups": [
    {
        "template_id": "ptid:1a5n2i6d3OYEAAAAAAAAAYa",
        "fields": [
            {
                "name": "Security Policy",
                "value": "Confidential"
            }
        ]
    }
],
"has_explicit_shared_members": false,
"content_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"

}

在此处查看完整的详细信息:https://www.dropbox.com/developers/documentation/http/documentation#files-download

Dropbox 选择器是从 Dropbox 获取文件的最快方式

https://www.dropbox.com/developers/chooser

在演示部分,select 直接 link 并选择 dropbox 文件直接创建 link。

登录 SSH 并导航到要下载并粘贴命令的文件夹

curl -O 'url'