我知道已经有类似的问题,但所有的答案大多是“哦,我忘了把斜线放在最后”但这绝对让我发疯。我试图从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:// s删除了搜索通配符,但我无法摆脱这个错误...感谢任何帮助。
答案 0 :(得分:0)
重构后我自己遇到了同样的问题,并且自己发疯了。发布请求中的redirect_uri
必须与客户端第一个redirect_uri
相同。来自Spotify docs:
必需的。 此参数仅用于验证(没有实际的重定向)。此参数的值必须与请求授权码时提供的redirect_uri值完全匹配。