我相信你可以找到在這裏登錄用戶和上傳數據的所有信息:
Dropbox - Using the Core API in PHP
正如你可以看到你應該創建一個應用程序,獲得訪問令牌(谷OAuth2流程)和代表用戶使用這個API發出請求。如果你需要讓你的用戶在你的網站,你可以涉及Ajax構建結構進行了登錄,授權等方面的電話..
基本上這些步驟如下:
// Include Dropbox PHP Sdk and create a new AuthBase instance (WebAuthNoRedirect is a subclass of).
$dropboxAppAuth = new dbx\WebAuth($yourAppInfo, "examples-authorize", new dbx\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token'););
// Get an authorize url
$authorizeUrl = $dropboxAppAuth->start();
// Invite the user to authorize your app via this url
echo "1. Go to: " . $authorizeUrl . "\n";
echo "2. Click \"Allow\" (you might have to log in first).\n";
...
// and get an access token from the GET array.
list($accessToken, $userId, $urlState) = $webAuth->finish($_GET);
// Now you need a Client instance to make you call using the API interface
$dropboxClient = new dbx\Client($accessToken, "examples-authorize");
$accountInfo = $dropboxClient->getAccountInfo();
// Get a file pointer resource from the resource you want to upload and send it using the `uploadFile()` method from the Dropbox API
$resourceFilename = 'my-data.txt';
$f = fopen($resourceFilename, "rb");
$result = $dropboxClient->uploadFile("/".$resourceFilename, dbx\WriteMode::add(), $f);
但是在你可以找到這個基本的例子,完成並準備開始玩它。
[僅限鏈接回答](http://meta.stackexchange.com/a/ 8259/246338) –
感謝您的幫助。 現在我已經將用戶從我的PHP應用程序導向auth url。 Dropbox要求登錄,登錄後它要求允許或拒絕。我允許並顯示授權碼,但沒有重定向到我的應用程序。它應該使用授權碼重定向到我的應用程序。我錯過了什麼? –
是的,很抱歉,我使用了'WebAuthNoRedirect',我應該使用正確的'WebAuth'。我編輯了答案,因爲你現在可以看到你還必須在構造函數中傳遞一個csrf類。然後你可以訪問重定向的url中的GET數組。請在這裏查看關於如何使用此類的詳細信息:https://github.com/dropbox/dropbox-sdk-php/blob/master/lib/Dropbox/WebAuth.php – ilpaijin