javascript - Spotify 白名单 URI 仍然返回 { "error": "invalid_grant", "error_description": "Invalid redirect URI"}

标签 javascript express spotify

我知道已经有类似的问题,但所有答案大多是“哦,我忘了在末尾加上斜线”但这绝对让我发疯。我试图从 Spotify API 获取访问 token ,但我一直收到无效的重定向 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://删除了搜索通配符,但我无法摆脱这个错误...感谢任何帮助。

最佳答案

经过一些重构后,我自己也遇到了同样的问题,我自己都快疯了。 post 请求中的 redirect_uri 必须与来自客户端的第一个 redirect_uri 相同。来自Spotify docs :

Required. This parameter is used for validation only (there is no actual redirection). The value of this parameter must exactly match the value of redirect_uri supplied when requesting the authorization code.

关于javascript - Spotify 白名单 URI 仍然返回 { "error": "invalid_grant", "error_description": "Invalid redirect URI"},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50191422/

相关文章:

javascript - 判断父容器子元素是否包含特定类并执行某些操作的条件

node.js - 在 Heroku 上部署 Nodejs 无法提供位于子文件夹中的静态文件

javascript - NodeJS ExpressJS 如何打印API结果数组?

javascript - 使用node.js ejsexpress显示mysql查询结果

c++ - 非法功能,Spotify 技术难题

javascript - asp 与 javascript

javascript - 缩小捆绑 JS 和外部库

android - 检测 Spotify 歌曲播放

javascript - 如何在 JavaScript 中表示代数数据类型和模式匹配

javascript - 如何在没有用户登录的情况下获取 Spotify 播放列表 JSON