我知道已经有类似的问题,但所有的答案大多是“哦,我忘了把斜杠放在最后”,但这绝对让我抓狂。我正在尝试从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删除了搜索通配符,但我无法摆脱这个错误……任何帮助都是非常感谢的。
发布于 2019-05-24 07:17:57
在一些重构之后,我自己也遇到了同样的问题,我自己也快要疯了。post请求中的redirect_uri
必须与来自客户端的第一个redirect_uri
相同。从Spotify docs
需要
。此参数仅用于验证(没有实际的重定向)。此参数的值必须与请求授权码时提供的redirect_uri的值完全匹配。
https://stackoverflow.com/questions/50191422
复制相似问题