【问题标题】:How to fix 'error: invalid_grant Invalid authorization code' when asking for reshresh_token from Spotify API?从 Spotify API 请求 reshresh_token 时,如何解决“错误:invalid_grant Invalid authentication code”?
【发布时间】:2019-12-28 07:27:54
【问题描述】:

我正在尝试为我的 Ionic 应用程序接收 refresh_token,但我成功接收了 access_token

我在我的 TypeScript 项目中从端点 https://accounts.spotify.com/authorize?client_id= 收到 codeauthorization_codeaccess_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"}

【问题讨论】:

    标签: javascript http-post spotify refresh-token insomnia


    【解决方案1】:

    所以经过两天的尝试,我找到了这个issue,在检查了文档后,我发现了我错了。问题是当你想刷新令牌时,你需要将 POST 请求的主体发送到 /api/token 端点code not access_token。就我而言,我正在发送 access_token。要接收代码,您应该向https://accounts.spotify.com/authorize 端点发送相同的请求,但带有参数response_type=code

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-21
      • 2021-08-07
      • 2021-10-29
      相关资源
      最近更新 更多