【问题标题】:Spotify WebAPI authorization - client credentials flow error invalid_clientSpotify Web API 授权 - 客户端凭据流错误 invalid_client
【发布时间】:2014-11-20 13:12:04
【问题描述】:

直截了当的问题,希望有直截了当的答案。我正在尝试使用请求通过 Node.js 实现客户端凭据流。这是我的代码

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,这让我相信这是导致问题的编码。

我的编码正确吗?如果有,还有什么原因?

【问题讨论】:

    标签: node.js spotify


    【解决方案1】:

    替换

    "Authorization": "Bearer " + ...
    

    "Authorization": "Basic " + ...
    

    看看效果好不好。

    【讨论】:

    • 哦,哇,我觉得自己很傻。我真的应该更多地关注我正在阅读的内容。这是一种享受。感谢您的帮助。
    猜你喜欢
    • 2022-06-25
    • 1970-01-01
    • 2021-01-10
    • 2018-08-22
    • 2019-05-03
    • 2021-10-19
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多