javascript - 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'])
})
这是错误:
解决方案
您是否确保在 .append("refresh_token", token) 中作为参数传递的令牌是 API 最初提供的刷新令牌而不是访问令牌?根据参数的名称,您可能会传递初始 access_token,这将导致 status:400 错误。
通过授权流程的初始请求将为您提供两者。当您请求新的刷新令牌时,请确保提供此时收到的刷新令牌,它应该可以工作。
推荐阅读
- swift - Why does `infix operator $` produce contradictory error messages in Swift?
- python - 我可以将 lambda 函数应用于特定行的 df 列吗?
- ios - How do I download this image from this URL using URLSession?
- c# - Updates a single work item Azure Devops using Asp.net
- r - How can I merge two dataframes equivalently to VLookup criteria?
- node.js - 使用 Jest 中的类搜索实体时出现 TypeORM RepositoryNotFoundError
- postgresql - 在 eloquent / Laravel 更新期间发现意外数据
- wordpress - 没有定义模板 wordpress masterstudy
- javascript - react js匹配具有相似数据的行
- c# - 如何发送“安全电子邮件”?