【发布时间】:2026-01-12 13:35:01
【问题描述】:
在使用 Meteor HTTP 在 Spotify API 上请求 access_token 时,我无法解决问题。事实上,当我对 Spotify https://accounts.spotify.com/api/token 进行 POST 调用时。我得到以下回复:
{"statusCode":400,"content":"{\"error\":\"unsupported_grant_type\",\"error_description\":\"grant_type must be client_credentials, authorization_code or refresh_token\"}"
我认为这可能与 Content-Type 标头和 BODY 参数的编码有关,但我无法解决此问题。我尝试同时使用数据和参数,但这些都不起作用。
这是我的代码:
HTTP.post("https://accounts.spotify.com/api/token", {
data: {
grant_type : "authorization_code",
code : authCode,
redirect_uri : Router.routes['redirect_spotify'].url()
},
headers: {
'Authorization' : "Basic " + CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse("xxxx:yyyyy")),
'Content-Type':'application/x-www-form-urlencoded'
}
}, function(error, result) {
console.log("POST made with data : %j", result);
if (error){
Registrations.remove({userId : this.userId });
return;
}
Registrations.update({
userId : this.userId },
{$set : {
state: "Done",
accessToken: result.access_token,
//TODO expires
refreshToken: result.refresh_token
}},
{ upsert : true}
);
});
提前谢谢大家:)爱流星
【问题讨论】:
-
我假设您将“authorization_code”替换为您的授权码,对吧?
-
authorization_code 是一个定义授权方案的字符串。授权码在代码中
标签: javascript http meteor http-post spotify