当从Spotify API请求reshresh_Token时,如何修复错误:INVALID_GRANT INVALID授权码';? [英] How to fix 'error: invalid_grant Invalid authorization code' when asking for reshresh_token from Spotify API?
本文介绍了当从Spotify API请求reshresh_Token时,如何修复错误:INVALID_GRANT INVALID授权码';?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试接收refresh_token
对于我的Ionic应用程序,我成功接收access_token
。
我从终结点https://accounts.spotify.com/authorize?client_id=
接收code
(authorization_code
或access_token
)在我的TypeScrip项目中,我将其传递给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"}
推荐答案
因此,经过两天的尝试,我发现了issue,并且在查看文档后,我找到了我错的地方。问题是,当您想要刷新令牌时,您需要在POST请求正文中发送到/api/Token端点代码,而不是Access_Token。在我的例子中,我发送的是Access_Token。若要接收代码,您应该向https://accounts.spotify.com/authorize终结点发送相同的请求,但参数为response_type=code
。
这篇关于当从Spotify API请求reshresh_Token时,如何修复错误:INVALID_GRANT INVALID授权码';?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文