使用 curl 通過程式碼授予獲取 Dropbox API 的 OAuth 2 訪問令牌

縮寫為 https://blogs.dropbox.com/developers/2013/07/using-oauth-2-0-with-the-core-api/

第 1 步:開始授權

將使用者傳送到此網頁,並填寫你的值:

https://www.dropbox.com/oauth2/authorize?client_id=<app key>&response_type=code&redirect_uri=<redirect URI>&state=<CSRF token>

授權程式碼將作為重定向 URI 上的 code 引數包含在內。

第 2 步:獲取訪問令牌

curl https://api.dropbox.com/oauth2/token -d code=<authorization code> -d grant_type=authorization_code -d redirect_uri=<redirect URI> -u <app key>:<app secret>

第 3 步:呼叫 API

在 API 呼叫中,設定標題:

Authorization: Bearer <access token>

檢視部落格文章瞭解更多詳細資訊,包括使用 state 防止 CSRF 攻擊的重要安全說明。