0
votes

I'm trying to get a token from Spotify using the Web API:

My raw request:

POST https://accounts.spotify.com/api/token HTTP/1.1
Authorization: Basic [authsecret]
Content-Type: application/x-www-form-urlencoded
Host: accounts.spotify.com
Content-Length: 490
Expect: 100-continue
Connection: Keep-Alive

grant_type=authorization_code&code=[code]&redirect_url=http%3A%2F%2Flocalhost%3A53575%2FSpotifyLogin.aspx

Where [authsecret] is replaced by the required string (this was broken and gave me a different error, but now I fixed it) and [code] is replaced by the code returned a step earlier by Spotify.

I get the following response:

HTTP/1.1 400 Bad Request
Server: nginx
Date: Thu, 22 Jun 2017 13:50:33 GMT
Content-Type: application/json
Content-Length: 68
Connection: keep-alive
Keep-Alive: timeout=600

{"error":"invalid_grant","error_description":"Invalid redirect URI"}

I must be doing something wrong, but I can't figure it out. Can anyone help me?

1
Is your app registered to the Spotify? - Daniel Mizerski
Yes. I registered the app with Spotify. It has proven to work as well, because I do get a callback with the code. - Jonathan van de Veen
I also just tested with an invalid redirect uri in this call. It would give me an INVALID CLIENT error instead of invalid_grant - Jonathan van de Veen
I just tested what happens when I send the redirect url unencoded, but it results in the same response. - Jonathan van de Veen

1 Answers

1
votes

I've figured it out. Issue is the parameter name redirect_url. It should be redirect_uri. Small mistake but breaks the request as it should.