问题
I want to download the files from dropbox and need to keep it in my server on behalf of dropbox user. I tried with curl and file_get_contents. But could not succeed. Should I need to use any api method of dropbox ? I could able to download the file from browser but I need to keep it in server. My application is a kind of file sharing.
回答1:
The Dropbox browser client is developed to be used by the Registered Users only, where user needs to sign-in and then he can access files there.
But as you said you want to access Dropbox files, on behalf of the users, you need to make use of the Dropbox Core APIs, you can use PHP Dropbox SDK to build your own application. I don't think there is any other way.
As you have mentioned, you want to access files from Dropbox on behalf of user, I guess you might be thinking of it without user interaction, but there is a catch in it, Dropbox makes use of OAuth 1.0 or 2.0, and in both the methods, you need to have user interaction. (For More Read Here)
Also you said, your application is a kind of File Sharing
, So do take a look at Dropbox App Review Process, which prohibits publically searchable File Share
applications.
Don't build file sharing apps
Dropbox doesn't support building publicly searchable file sharing networks on top of Dropbox.
回答2:
You can use the Dropbox public link to the file and use file_get_contents
and file_put_contents
.
Vanilla PHP example below.
<?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's from the service provider are usually the best way to access their data. It'd certainly be better this method.
My only note is: careful not to break Dropbox's ToS.
回答3:
Dropbox chooser is fastest way to get files from Dropbox
https://www.dropbox.com/developers/chooser
Under demo section, select direct link and choose dropbox file to create direct link.
Login to SSH and navigate to folder where you want to download & paste the command
curl -O 'url'
回答4:
you can use /download. it will return response like following:
{
"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"
}
See complete details here: https://www.dropbox.com/developers/documentation/http/documentation#files-download
来源:https://stackoverflow.com/questions/28019911/download-file-from-dropbox-to-the-server