首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Spotify白名单URI仍然返回{ "error":"invalid_grant","error_description":“无效重定向URI”}

Spotify白名单URI仍然返回{ "error":"invalid_grant","error_description":“无效重定向URI”}
EN

Stack Overflow用户
提问于 2018-05-06 00:03:49
回答 1查看 2.3K关注 0票数 6

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

下面是我的api调用

代码语言:javascript
复制
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:// s删除了搜索通配符,但我无法摆脱这个错误……任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

发布于 2019-05-24 07:17:57

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

需要

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

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50191422

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档