首页 > 解决方案 > Spotify api 刷新令牌返回错误 400

问题描述

我尝试刷新 Spotify 令牌,但服务器返回 400 错误。我使用 angularjs 和打字稿

let httpParams = new HttpParams()
  .append("grant_type", "refresh_token")
  .append("refresh_token", token)
  .append("client_id", my_client_id);

  this.http.post("https://accounts.spotify.com/api/token", httpParams.toString(), 
  { headers: { 
    'Content-Type':'application/x-www-form-urlencoded'
  },}).subscribe(data => {  
    console.log(data['access_token'])
  })

这是错误:

标签: javascriptangulartypescriptionic-frameworkspotify

解决方案


您是否确保在 .append("refresh_token", token) 中作为参数传递的令牌是 API 最初提供的刷新令牌而不是访问令牌?根据参数的名称,您可能会传递初始 access_token,这将导致 status:400 错误。

通过授权流程的初始请求将为您提供两者。当您请求新的刷新令牌时,请确保提供此时收到的刷新令牌,它应该可以工作。


推荐阅读