Search code examples
pythonwebspotify

Spotify API token issue


as the title suggests, I want to get in the form of JSON file the contents of my Spotify library, mainly liked songs and playlists. Spotify provides a web API for that, but I am not experienced with web applications.

However I am experienced with Python, and I try to implement what the Spotify for Developers Documentation on the site suggests with Python.

Firstly, I have to request for an Access token which is used in every HTTP request. I follow the instructions here, and Request User Authentication section, the GET request that I do for getting the callback responds with

'{ "error": { "status": 401, "message": "No token provided" } }'

The thing is that I send this request in order to get the Access token. This is my code:

import requests


uri_redirect = 'http://localhost:8888/callback'
authorize_endpoint = 'https://api.spotify.com/authorize'
request_authorization_parameters = {'client_id': 'here I give my client id',
                                    'response_type': 'code',
                                    'redirect_uri': uri_redirect,
                                    'scope': 'user-library-read playlist-read-private'}
r_auth = requests.get(authorize_endpoint, params=request_authorization_parameters)

What am I doing wrong?

Cheers!


Solution

  • After all, it was a careless mistake. I used wrong URL for the authorization endpoint.

    The request must be sent to https://accounts.spotify.com/authorize instead of https://api.spotify.com/authorize.

    Following the rest of the documentation, I had no problem.