小编cro*_*rer的帖子

从 Spotify 请求访问令牌时出现“仅支持有效的承载身份验证”错误

我正在尝试从 Spotify 获取 oAuth 访问令牌(他们的指南中的第 4 步)。

我相信,我按照他们的文档中的描述发送了所有必需的参数,但 Spotify 回应:

"error": {
    "status": 400,
    "message": "Only valid bearer authentication supported"
}
Run Code Online (Sandbox Code Playgroud)

这是我在 node.js 中的请求:

function getToken(code){
    var idAndSecret = config.clientId+':'+config.clientSecret;
    var authString = 'Basic ' + new Buffer(idAndSecret).toString('base64');
    var data = querystring.stringify({
        grant_type: "authorization_code",
        code: code,
        redirect_uri: REDIRECT_URI
    });
    var tokenReq = https.request({
        hostname: 'api.spotify.com',
        path: '/api/token?'+data,
        method: 'POST',
        headers: {
            'Authorization': authString
        }
    }, function(res){
        res.on('data', function(chunk){
            console.log(new Buffer(chunk).toString());
        });
        console.log(res.statusCode, JSON.stringify(res.headers));
    });

    tokenReq.end();
}
Run Code Online (Sandbox Code Playgroud)

我已经检查了我的 clientId、clientSecret、auth-code …

spotify node.js

3
推荐指数
1
解决办法
4688
查看次数

标签 统计

node.js ×1

spotify ×1