Reputation: 363
I'm facing an issue that I don't understand! I am developing a react-native (js) app which try to access Spotify api using the Implicit Grant Flow.
Here is my method to get the access token:
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);
}
}
but It answers that:
Missing required parameter: client_id
I also used Postman to check if my request is good and I get the same response...
Is there something wrong? On their doc they tell that it is a GET method with only 3 parameters..
Thank you in advance for any workaround!
Upvotes: 0
Views: 1174
Reputation: 24670
You are giving query parameters as options to fetch
rather than adding it to the url.
change this
fetch('https://accounts.spotify.com/authorize', query).then(function () { ... })
to this
fetch(`https://accounts.spotify.com/authorize${query}`).then(function () { ... })
Upvotes: 1