我正在使用Spotify API(特别是https://api.spotify.com/v1/recommendations处的建议端点)并且我一直使用消息&#34来获得状态代码400;仅支持有效的承载身份验证"。以下是相关的代码段:
let token = body.access_token; //gives access token
let token_type = body.token_type; //gives the string 'Bearer'
let options = {
url: 'https://api.spotify.com/v1/recommendations?' +
querystring.stringify({
min_danceability: 1.0,
min_energy: 0.5
}),
//Formats the header as {Authorization: Bearer {token}}
headers: {'Authorization': `${token_type} ${token}`},
json: true
};
request(options, (error,response,body) =>{
if (!error && response.statusCode === 200) {
console.log(body);
}
else {
//This always seems to console.log statusCode 400
console.log(response.statusCode);
}
});
编辑:对于发现这篇文章的人,我想出来了。使用建议端点时,必须至少包含seed_genres,seed_artists或seed_tracks中的一个。否则,端点将继续返回400 Only Valid Bearer Authentication Supported错误。