Spotify Implicit Grant Flow-缺少必需参数:client_id

时间:2017-09-15 06:03:48

标签: javascript asp.net-web-api react-native spotify

我正面临一个我不明白的问题! 我正在开发一个react-native(js)应用程序,尝试使用Implicit Grant Flow访问Spotify api。

以下是获取访问令牌的方法:

async function getTokenFromAPI() {
    try {
        var params = {
            client_id: '<client_id>',
            response_type: 'token',
            redirect_uri: 'http://localhost:8888/callback'
        };

        var esc = encodeURIComponent;
        var query = Object.keys(params)
            .map(k => `${esc(k)}=${esc(params[k])}`)
            .join('&');

        fetch('https://accounts.spotify.com/authorize', query).then(function (response) {
            console.log('response, ' + JSON.stringify(response));
            return response;
        })
    } catch(error) {
        console.error(error);
    }
}

但是答案是: Missing required parameter: client_id

我还使用Postman来检查我的请求是否合适,并得到相同的回复......

有什么问题吗?在他们的doc上,他们告诉他这是一个只有3个参数的GET方法..

提前感谢您的任何解决方法!

1 个答案:

答案 0 :(得分:0)

您将查询参数作为选项提供给fetch,而不是将其添加到网址。

更改此

fetch('https://accounts.spotify.com/authorize', query).then(function () { ... })

到这个

fetch(`https://accounts.spotify.com/authorize${query}`).then(function () { ... })
相关问题