I'm trying to authenticate a user in the Spotify API, but it keeps returning me the error code "invalid_client". I'm implementing that on a Python Django solution, that's my code:
headers = {'Authorization': 'Basic '+standard_b64encode(client_id)+standard_b64encode(client_secret)}
r = requests.post('https://accounts.spotify.com/api/token', {'code': code, 'redirect_uri': redirect_uri, 'grant_type': grant_type, 'headers': headers}).json()
Any idea why it's not working?
Are you sure you're providing
client_id
&client_secret
in the proper format? Looking at the docs, it suppose to be separated with:
.Also try to run the same flow with curl first and then replicate with python.
In spotify api docs it is: Authorization Required. Base 64 encoded string that contains the client ID and client secret key. The field must have the format: Authorization: Basic base64 encoded( client_id:client_secret)
So i guess you should do:
It's working for me so try it. If it doesn't work my code is:
Hope it helps!