Spotify WebAPI授权 – 客户端凭据stream错误invalid_client

直截了当的问题,希望用一个直截了当的答案。 我试图通过Node.js使用请求来实现客户端证书stream。 这是我的代码

var request = require('request'); var payload = config.spotify.clientID + ":" + config.spotify.clientSecret; var encodedPayload = new Buffer(payload).toString("base64"); var opts = { url: "https://accounts.spotify.com/api/token", method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", "Authorization": "Bearer " + encodedPayload }, body: "grant_type=client_credentials&scope=playlist-modify-public playlist-modify-private" }; request(opts, function (err, res, body) { console.log('error', err); console.log('status', res.statusCode); console.log('body', body); }); 

无论我做什么,反应机构总是

 {"error":"invalid_client"} 

我试着用curl来做这个请求,结果是一样的。

 $ curl -X POST -H 'Authorization: Bearer <base64encoded client_id:client_secret>' -d 'grant_type=client_credentials&scope=playlist-modify-public playlist-modify-private' https://accounts.spotify.com/api/token 

这意味着这是凭证的问题。 我肯定使用正确的clientID和clientSecret为我的应用程序,这导致我相信这是导致问题的编码。

我在做编码吗? 如果是的话,还有什么可能的原因呢?

更换

 "AUthorization": "Bearer " + ... 

 "Authorization": "Basic " + ... 

看看它是否更好。