[英]WebapiAuthenticationError: An authentication error occurred while communicating with Spotify's Web API. Details: invalid_grant Invalid redirect URI
[英]How to fix 'error: invalid_grant Invalid authorization code' when asking for reshresh_token from Spotify API?
我正在尝试为我的Ionic应用程序接收refresh_token
,我成功接收了access_token
。
我在TypeScript项目中从端点https://accounts.spotify.com/authorize?client_id=
接收code
( authorization_code
或access_token
),然后将其传递给cURL
以测试如何获取refresh_token
但这是我唯一收到的错误。
curl -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Basic MzBhNT...ZWIyZWQ=" -d grant_type=authorization_code -d code=BQAjgZOFne3p8PB4ARJkrXtq...kI4xJvhQ7SutZoJqVWILCY -d redirect_uri=http%3A%2F%2Flocalhost%3A8100%2Fmain -X POST https://accounts.spotify.com/api/token
预期产量:
{
"access_token": "NgCXRK...MzYjw",
"token_type": "Bearer",
"scope": ...,
"expires_in": 3600,
"refresh_token": "NgAagA...Um_SHo"
}
但收到错误:
{"error":"invalid_grant","error_description":"Invalid authorization code"}
因此,经过两天的尝试,我发现了这个问题,并且在检查了文档之后,发现我错了。 问题是,当您想刷新令牌时,需要将POST请求的正文发送到/ api / token端点代码而不是access_token 。 就我而言,我正在发送access_token。 要接收代码,您应该将相同的请求发送至https://accounts.spotify.com/authorize端点,但参数为response_type=code
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.