Persistent issues with Spotify Web API redirect URI

977 Views Asked by At

I know this has been posted about multiple times but I've tried all the solutions I've found on SO and none have worked. I'm trying to retrieve user data about myself from Spotify's Web API by following simple examples like the ones posted here and here. So I've now tried both Spotify and tekore but neither are working for me.

The closest I've come to making it work is by following this example. When I run that code in a Jupyter Notebook, a separate window pops open and prompts me to agree to authorize access to my data. When I select "Agree" I get an "ERR_TOO_MANY_REDIRECTS" error and the suggestion to clear my cookies, which I've done multiple times now.

And when I enter my redirect URI in the prompt that pops up in the notebook, I get the following error: "KeyError: 'Passed URL contains no parameter code!'"

I am using "http://localhost:8888/callback/" as the redirect URI and I've double-checked to make sure the whitelisted URI matches what I'm using in my notebook. Any suggestions as to what I'm doing wrong?

Lastly, here's the code I'm trying:

import tekore as tk

# Read in keys
client_id = open('./spotify-client-id.txt', 'r').read().rstrip('\n')
client_secret = open('./spotify-client-secret.txt', 'r').read().rstrip('\n')

# Set URI
redirect_uri = 'http://localhost:8888/callback/'

conf = (client_id, client_secret, redirect_uri)
token = tk.prompt_for_user_token(*conf, scope=tk.scope.every)

spotify = tk.Spotify(token)
tracks = spotify.current_user_top_tracks(limit=10)
spotify.playback_start_tracks([t.id for t in tracks.items])
1

There are 1 best solutions below

4
seeess1 On

Apparently the trick is to ignore the error message, copy the URL from the browser, and paste it into the cell in your Jupyter Notebook.

spotipy should cache the response so that you don't have to go through this process each time. Thanks to murraypaul on Spotify's Community help forum for this advice.