0

Sorry for this title but i really need hlp. I don't know why that's not working and i searched a lot.

So I'm working with Spotify Api and I want to access to the Access_Token. The documentation says you have to do like that: Spotify Documentation

And I m requesting like this :

  fetch ('https://accounts.spotify.com/api/token', {
method: 'post',
body: {
  code: code,
  redirect_uri: redirectUri,
  grant_type: 'authorization_code'
},
headers: {
  'Content-Type': 'application/x-www-form-urlencoded',
  Authorization: 'Basic ' + btoa(clientId+':'+clientSecret)
},
json: true
 })

But that's answering this: Error

I checked and error 400 means "Bad Request".

Have u got an idea? Thanks for helping !

1 Answers1

0

Looking at your error, no body was received. You have to send it as a json string:

let body = {
  code: code,
  redirect_uri: redirectUri,
  grant_type: 'authorization_code'
}
fetch ('https://accounts.spotify.com/api/token', {
method: 'post',
body: JSON.stringify(body),
headers: {
  'Content-Type': 'application/x-www-form-urlencoded',
  Authorization: 'Basic ' + btoa(clientId+':'+clientSecret)
},
json: true
 })
Tom Roman
  • 125
  • 1
  • 8
  • Still not working :( That's the error: ```Failed to load resource: the server responded with a status of 400 ()``` – wshchocolatine Mar 10 '21 at 15:08
  • 400 would imply you're sending incorrect data. Is your clientId and secret correct? Can you try manually with something like Postman? – Tom Roman Mar 10 '21 at 16:31