0

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])
Felix
  • 2,548
  • 19
  • 48
seeess1
  • 155
  • 1
  • 1
  • 9

1 Answers1

0

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.

seeess1
  • 155
  • 1
  • 1
  • 9
  • Hey! Did you manage to find out why an error was thrown? Was it because of the notebook? Yes, caching or saving tokens to a database after authorisation is the way to go! See these links for [Spotipy](https://spotipy.readthedocs.io/en/2.16.1/#spotipy.oauth2.SpotifyOAuth) and [Tekore](https://tekore.readthedocs.io/en/stable/auth_guide.html#refreshing-and-saving-tokens). – Felix Jan 18 '21 at 13:56
  • @Felix yep the answer I posted above worked for me – seeess1 Jan 19 '21 at 14:07
  • I got that it worked, but did you manage to find out more about the error or are you continuing to ignore it? – Felix Jan 19 '21 at 15:58
  • Just ignoring it for now. Not sure what the root cause of the error is. – seeess1 Jan 20 '21 at 18:34