I’m stuck with a problem in my Ionic app. I’m trying to get a refresh_token from the Spotify API. I can get the access_token just fine, but when I try to exchange the authorization_code for a refresh_token, I keep getting an error.
Here’s what I’m doing:
- I get the
codefromhttps://accounts.spotify.com/authorize - I use this
codein a POST request tohttps://accounts.spotify.com/api/token
My request looks something like this:
POST /api/token HTTP/1.1
Host: accounts.spotify.com
Content-Type: application/x-www-form-urlencoded
Authorization: Basic Base64EncodedClientIDAndSecret
grant_type=authorization_code&code=MyAuthorizationCode&redirect_uri=http://localhost:8100/main
But instead of getting the refresh_token, I’m getting this error:
{
"error": "invalid_grant",
"error_description": "Invalid authorization code"
}
What am I doing wrong? How can I fix this and get the refresh_token?