我怎样才能获得 Amazon Cloud Drive 访问令牌?
how can I get Amazon Cloud Drive access token?
我正在尝试获取亚马逊云驱动器的访问令牌。
首先我要求这个 url:
https://www.amazon.com/ap/oa?client_id=MYCLIENTID&scope=clouddrive%3Aread_all%20clouddrive%3Awrite&response_type=code&redirect_uri=https://mymusic.az/signin
然后我点击继续。
之后我将重定向 URL:
https://mymusic.az/signin?code=SOMECODE&scope=clouddrive%3Aread_all+clouddrive%3Awrite
我从 URL 得到了 SOMECODE。但它不是访问令牌吗?
如何使用 SOMECODE 获取访问令牌?
就会很明显发生什么
有两种类型的授权,隐式授予 return 一个将过期的授权令牌,以及 return 一个不会过期的授权代码的授权码授予。您正在请求授权码,这就是您要返回的内容。然后,只要您需要检索访问令牌,您就可以使用授权代码发出另一个请求。至少我建议阅读标题为 "Authorization Code Grant".
的文档的整个部分
获得CODE后需要索取token
发送POST到https://api.amazon.com/auth/o2/token
内容类型 application/x-www-form-urlencoded
grant_type : set to 'authorization_code'.
code : Specifies the code returned after user authorization.
client_id : Specifies the identifier for the app. This is a body parameter.
client_secret : Specifies the secret identifier associated with the app.
redirect_uri : Specifies one of the return URIs that you added to your app when signing up.
应该是url编码形式,不是JSON。并且所有参数都是必需的,即使说 redirect_uri 在这里没用,但它应该与代码中使用的相同。
但作为回应你会得到 JSON 类似这样的东西
{
"token_type": "bearer",
"expires_in": 3600,
"refresh_token": "Atzr|IQEBLzAtAhUAibmh-1N0EVztZJofMx",
"access_token": "Atza|IQEBLjAsAhQ3yD47Jkj09BfU_qgNk4"
}
我正在尝试获取亚马逊云驱动器的访问令牌。 首先我要求这个 url:
https://www.amazon.com/ap/oa?client_id=MYCLIENTID&scope=clouddrive%3Aread_all%20clouddrive%3Awrite&response_type=code&redirect_uri=https://mymusic.az/signin
然后我点击继续。 之后我将重定向 URL:
https://mymusic.az/signin?code=SOMECODE&scope=clouddrive%3Aread_all+clouddrive%3Awrite
我从 URL 得到了 SOMECODE。但它不是访问令牌吗? 如何使用 SOMECODE 获取访问令牌?
有两种类型的授权,隐式授予 return 一个将过期的授权令牌,以及 return 一个不会过期的授权代码的授权码授予。您正在请求授权码,这就是您要返回的内容。然后,只要您需要检索访问令牌,您就可以使用授权代码发出另一个请求。至少我建议阅读标题为 "Authorization Code Grant".
的文档的整个部分获得CODE后需要索取token
发送POST到https://api.amazon.com/auth/o2/token 内容类型 application/x-www-form-urlencoded
grant_type : set to 'authorization_code'.
code : Specifies the code returned after user authorization.
client_id : Specifies the identifier for the app. This is a body parameter.
client_secret : Specifies the secret identifier associated with the app.
redirect_uri : Specifies one of the return URIs that you added to your app when signing up.
应该是url编码形式,不是JSON。并且所有参数都是必需的,即使说 redirect_uri 在这里没用,但它应该与代码中使用的相同。
但作为回应你会得到 JSON 类似这样的东西
{
"token_type": "bearer",
"expires_in": 3600,
"refresh_token": "Atzr|IQEBLzAtAhUAibmh-1N0EVztZJofMx",
"access_token": "Atza|IQEBLjAsAhQ3yD47Jkj09BfU_qgNk4"
}