Javascript 使用Meteor HTTP在Spotify API上请求access_令牌时出现不支持的授权类型错误
在使用Meteor HTTP在Spotify API上请求访问令牌时,我无法解决问题。事实上,当我给Spotify打电话后。我得到以下回应:Javascript 使用Meteor HTTP在Spotify API上请求access_令牌时出现不支持的授权类型错误,javascript,http,meteor,http-post,spotify,Javascript,Http,Meteor,Http Post,Spotify,在使用Meteor HTTP在Spotify API上请求访问令牌时,我无法解决问题。事实上,当我给Spotify打电话后。我得到以下回应: {"statusCode":400,"content":"{\"error\":\"unsupported_grant_type\",\"error_description\":\"grant_type must be client_credentials, authorization_code or refresh_token\"}" 我认为这可能与C
{"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}
);
});
提前感谢大家:)Love Meteor您需要使用
参数
而不是数据
。因此,您的代码是:
HTTP.post(“https://accounts.spotify.com/api/token", {
参数:{
授权类型:“授权代码”,
代码:authCode,
重定向_uri:Router.routes['redirect_spotify'].url()
},
标题:{
“授权”:“基本”+CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(“xxxx:yyyy”),
“内容类型”:“应用程序/x-www-form-urlencoded”
}
},函数(错误,结果){
...
});
当方法为POST时,在请求正文中以查询参数的格式发送数据也会起作用
例如:
将请求正文中的数据值name='Tommy'和age=26作为
name=Tommy&age=26
我假设您用授权码替换了“授权码”,对吗?授权码是定义授权方案的字符串。授权代码放在代码中这帮助我找到了使用
query
而不是body
来发布Swift Vapor HTTP post的方法。谢谢这解决了我在发送授权信息时遇到的问题