【问题标题】:Spotify Whitelisted URI still returns { "error": "invalid_grant", "error_description": "Invalid redirect URI" }Spotify 白名单 URI 仍然返回 { "error": "invalid_grant", "error_description": "Invalid redirect URI" }
【发布时间】:2018-10-15 21:57:40
【问题描述】:

我知道已经有类似的问题,但所有的答案大多是“哦,我忘了把斜线放在最后”但这绝对让我发疯。我试图从 Spotify API 获取访问令牌,但我不断收到无效的重定向 uri 错误。

这是我的 api 调用

const request = require('superagent');

const data = {
    grant_type: 'authorization_code',
    code: code,
   // redirect_uri: encodeURIComponent('http://localhost:3000/Test')
   redirect_uri: 'http://localhost:3000/Test'
};

request.post('https://accounts.spotify.com/api/token')
    .set({
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': 'Basic ' + base64.encode(configs.client_id + ':' + configs.client_secret)
    })
    .send(data)
    .end((err, tokenRes) => {
        if (tokenRes) {
            res.send({token: tokenRes})
        } else {
            res.error(err);
        }
    });

这些是我列入白名单的 URI:

http://localhost:3000/LoginRedirect

http://localhost:3000/Test

http://localhost:3000/Home

我在白名单中添加了很多组合,末尾带有斜杠,http:// 已删除搜索通配符,但我无法摆脱此错误...感谢任何帮助。

【问题讨论】:

    标签: javascript express spotify


    【解决方案1】:

    在进行了一些重构之后,我自己也遇到了同样的问题,我自己都快疯了。发布请求中的redirect_uri 必须与来自客户端的第一个redirect_uri 相同。来自Spotify docs

    必填。 此参数仅用于验证(没有实际重定向)。此参数的值必须与请求授权码时提供的 redirect_uri 的值完全匹配。

    【讨论】:

    • 是的.. 这有点误导,但这解决了它。
    猜你喜欢
    • 2020-03-31
    • 1970-01-01
    • 2015-09-17
    • 2015-01-02
    • 2022-01-09
    • 2012-05-14
    • 2020-09-01
    • 2013-10-22
    • 2021-01-20
    相关资源
    最近更新 更多