在使用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\"}"
Run Code Online (Sandbox Code Playgroud)
我认为这可能与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}
);
}); …Run Code Online (Sandbox Code Playgroud)