使用 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 攻击的重要安全说明。