0

I know this has been posted before but I am unable to get their solutions to work.

Every time I authorise my Spotify account after running my code, it asks me to paste my redirect URI into the terminal, but every time I do that, it throws an error. I am using Python 3.9 and Tekore version 4.5.0.

I have whitelisted the site on the Spotify developer dashboard (I tried Youtube because the default 'example.com/callback' threw a similar error). I tried a few different sites, each throwing up a slightly different error message, but ultimately from the same source something is wrong with the site.

What I expect to happen is that once I authorise my Spotify account, it takes me to the redirect site and then saves authorisation information locally, but it doesn't save the information locally and throws an error, like shown above. Finally, here is the code.

import tekore as tk

client_id = '' #ids are missing intentionally
client_secret = '' 
token = tk.request_client_token(client_id, client_secret)

# Call the API
spotify = tk.Spotify(token)


# Use the response
for track in album.tracks.items:
    print(track.track_number, track.name)

redirect_uri = 'https://youtube.com'

user_token = tk.prompt_for_user_token(client_id, client_secret, redirect_uri, scope=tk.scope.every)

conf = tk.config_from_file('tekore.cfg', return_refresh=True)
user_token = tk.refresh_user_token(*conf[:2], conf[3])

conf = (client_id, client_secret, redirect_uri, user_token.refresh_token)
tk.config_to_file('tekore.cfg', conf)

spotify.playback_start_tracks('2Gt7fjNlx901pPRkvBiNBZ?si=9a9b8c9ca1634041')
Keamon
  • 1
  • 2
  • Using Flask and Request for get user token and song tracks in [here](https://stackoverflow.com/questions/75419872/spotify-api-getting-404-as-a-response-trying-to-find-current-song/75424917#75424917). I tested the `tekore` but it did not work. It asked the redirect URL on prompt and did not pick up `code`. – Bench Vue Jun 07 '23 at 23:38
  • Hi! It's likely an issue with the final redirect, and the resulting URL containing `code`. If you redirect to a random public website, they might strip the parameter out. In that sense, either localhost (when running locally) or your actual server (once you deploy an application) are the ways to go. Could you tell me if after the final redirect, you can see something along the lines of `?code=...` in the address bar? -- Then also a side note, in your code above, you probably mean to save the config to file *before* eventually reading it from the file. – Felix Jun 19 '23 at 05:39
  • @Felix I changed my redirect uri to https://example.com, and it now throws the error "no parameter 'state'", but it does include ?code in the url. How do I get it to include state? Sorry I am very new to this, as I'm using tekore as part of a school project. – Keamon Jun 21 '23 at 09:13
  • @Keamon I'd urge you to use localhost:5000/callback or something like that, just to be sure that the website isn't messing with it. `prompt_for_user_auth` sends the state and expects the corresponding state back. So if it's missing, something went wrong in the process. You getting the `code` parameter tells me that you're on the right track though! Are you sure the state isn't later on in the url? – Felix Jun 21 '23 at 12:27

0 Answers0