Spotipy: Authorization documentation changes

Created on 30 May 2017  路  8Comments  路  Source: plamere/spotipy

It seems like Spotify has changed the authorization requirements for the API's endpoints.

All endpoints now require authorization, so things like searching and fetching tracks need an access token. The Spotipy docs has an example of a Non-Authorized request, but those no longer work.

documentation

Most helpful comment

First of all create an app on https://beta.developer.spotify.com/dashboard/ and note down your Client ID, Client Secret and Redirect URI.


To authorize your API calls without going through the headache of verifying the redirect URL. Just make use of the oauth2 method:

import spotipy
import spotipy.oauth2 as oauth2

credentials = oauth2.SpotifyClientCredentials(
        client_id=client_id,
        client_secret=client_secret)

token = credentials.get_access_token()
spotify = spotipy.Spotify(auth=token)

Note that this method does not need any scope/redirect url and will only allow access to publicly available information.


To gain access to user's personal information, you need to use the old school util method (requires verifying of redirect URL):

import spotipy
import spotipy.util as util

token = util.prompt_for_user_token(
        username=your_username,
        scope=scope,
        client_id=client_id,
        client_secret=client_secret,
        redirect_uri=redirect_uri)

spotify = spotipy.Spotify(auth=token)

Learn more about using scopes from the official docs.

All 8 comments

I succeeded searching for items using the Client Credentials Flow

Yup! I think Spotipy's docs should be changed to reflect that.

If you want the examples to work with updated authorisations, here's what you need to do:

1.) Get a CLIENT ID and CLIENT SECRET (https://developer.spotify.com/web-api/tutorial/)
2.) According to the Client Credentials Flow, modify the example scripts in the following manner:

Line 3: from spotipy.oauth2 import SpotifyClientCredentials
Line 4: client_credentials_manager = SpotifyClientCredentials(client_id='YOUR ID', client_secret='YOUR SECRET ID')

At the end of a script, modify the sp = spotipy.Spotify() to
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

Then it /should/ work.

First of all create an app on https://beta.developer.spotify.com/dashboard/ and note down your Client ID, Client Secret and Redirect URI.


To authorize your API calls without going through the headache of verifying the redirect URL. Just make use of the oauth2 method:

import spotipy
import spotipy.oauth2 as oauth2

credentials = oauth2.SpotifyClientCredentials(
        client_id=client_id,
        client_secret=client_secret)

token = credentials.get_access_token()
spotify = spotipy.Spotify(auth=token)

Note that this method does not need any scope/redirect url and will only allow access to publicly available information.


To gain access to user's personal information, you need to use the old school util method (requires verifying of redirect URL):

import spotipy
import spotipy.util as util

token = util.prompt_for_user_token(
        username=your_username,
        scope=scope,
        client_id=client_id,
        client_secret=client_secret,
        redirect_uri=redirect_uri)

spotify = spotipy.Spotify(auth=token)

Learn more about using scopes from the official docs.

Thank you very much

First of all create an app on https://beta.developer.spotify.com/dashboard/ and note down your _Client ID_, _Client Secret_ and _Redirect URI_.

To authorize your API calls without going through the headache of verifying the redirect URL. Just make use of the oauth2 method:

import spotipy
import spotipy.oauth2 as oauth2

credentials = oauth2.SpotifyClientCredentials(
        client_id=client_id,
        client_secret=client_secret)

token = credentials.get_access_token()
spotify = spotipy.Spotify(auth=token)

Note that this method does not need any scope/redirect url and will only allow access to publicly available information.

To gain access to user's personal information, you need to use the old school util method (requires verifying of redirect URL):

import spotipy
import spotipy.util as util

token = util.prompt_for_user_token(
        username=your_username,
        scope=scope,
        client_id=client_id,
        client_secret=client_secret,
        redirect_uri=redirect_uri)

spotify = spotipy.Spotify(auth=token)

Learn more about using scopes from the official docs.

Damn, I'm late to the party but is there a way I can get the user private info without pasting the URL? I'm trying to buiild an app but this is killing me, lol.

Damn, I'm late to the party but is there a way I can get the user private info without pasting the URL? I'm trying to buiild an app but this is killing me, lol.

@JeanPaiva42 There's a PR (#243) that handles this by using a local http server to listen to the redirect and get the access code. I took a similar approach in my application to handle this issue before noticing the PR and it works very well.

If you want the examples to work with updated authorisations, here's what you need to do:

1.) Get a CLIENT ID and CLIENT SECRET (https://developer.spotify.com/web-api/tutorial/)
2.) According to the Client Credentials Flow, modify the example scripts in the following manner:

Line 3: from spotipy.oauth2 import SpotifyClientCredentials
Line 4: client_credentials_manager = SpotifyClientCredentials(client_id='YOUR ID', client_secret='YOUR SECRET ID')

At the end of a script, modify the sp = spotipy.Spotify() to
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

Then it /should/ work.

Thank you very much, this worked for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IzHoBX picture IzHoBX  路  4Comments

DylanMeeus picture DylanMeeus  路  4Comments

astralmedia picture astralmedia  路  4Comments

Kurchunk picture Kurchunk  路  3Comments

sheheryarbutt picture sheheryarbutt  路  5Comments