Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Redirect URI needed?

Redirect URI needed?

I just started working with Spotify's Web API and am using Python/Spotipy to retrieve data. If I want to retrieve data related specifically to my personal account (like recently played tracks or saved albums), do I need to set a redirect URI in my application settings? If so, what's a quick and easy URI that I could use?

 

I'm not building a public facing application as of now - I just want to retrieve historical data about my own Spotify usage. So I'm following the examples posted on Spotipy's GitHub (like this one: https://github.com/plamere/spotipy/blob/master/examples/user_playlists.py) but I'm getting the following error:

 

"SpotifyOauthError: No redirect_uri. Pass it or set a SPOTIPY_REDIRECT_URI environment variable."

Reply
21 Replies

If you are using spotipy, the redirect URI doesn't matter, just use http://localhost/

Spotipy will display a URL, open that in a browser and copy and paste back the response code.

Hi murraypaul and thanks for replying! I tried your suggestion to use "http://localhost/" as the redirect URI (and I double checked to make sure that my app settings have the same URI) but I get an error:

 

localhost-error.png

 

I'm just going off of the example under "Quick start" in the docs and running the following code in a Jupyter Notebook:

 

import spotipy
from spotipy.oauth2 import SpotifyOAuth

scope = "user-library-read"

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))

results = sp.current_user_saved_tracks()
for idx, item in enumerate(results['items']):
    track = item['track']
    print(idx, track['artists'][0]['name'], " – ", track['name'])

 

I've tried other things, like using "http://localhost:8888/callback/" as the URI but nothing seems to work. I keep getting errors.

You will get an error, but you just need to capture the URL you are redirected to, and give that to Spotipy when it asks for it.

 

What should happen is:

a) Spotipy opens a browser and connects to the authorisation service.

b) The authorisation service redirects your browser to http://localhost?code=...

c) Spotipy shows a prompt: "Enter the URL you were redirected to:"

d) You copy the entire URL from your browser address bar and paste it into the console window python is running in. 

 

It is quite clunky, but you only need to do it the first time you request a new type of access, spotipy will cache the responses.

 

Alternatively, if you have a publicly addressable IP, you can specify your redirect URL as http://hostname.domain:port/, and spotipy will spin up a temporary web server on that port to handle the redirect. I have not used that myself, however.

Awesome it worked! Thanks so much.

 

On a related note, I tried following Spotify's Quick Start directions for setting up a server-side application with Node.js but I'm getting an error at the "Running the Application" step. I can get to step 3 of that section but when I click on the login button the browser goes to a page that says "INVALID_CLIENT: Invalid redirect URI." In the docs it looks like that step should take me to a login page where I can input my Spotify username and password.

 

Any ideas what I'm doing wrong?

Make sure the URL you added as redirect_uri is included in your Redirect URIs.

1 - Go to your dashboard

2 - Click on edit settings

3 - Add the URL under Redirect URIs, press Add

4 - Save

 

For posterity, I was stuck on this issue until I tried "http://localhost" instead of "http://localhost/". The latter was taking me to a page that said it was an invalid URL, while the former took me to a page where I could click on a button allowing the app to have access to stuff, idk what it said but you get the gist. When using the former, it lined up with the other comments (click yes, copy paste the new url into python, and smile cause it works)

The redirect URI needs to include a port number, for example https://localhost:8080

very helpful, thank you!

 

here's how I did it for username: 

import os

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials

cid = <YOUR CLIENT ID>

secret = <YOUR CLIENT SECRET>

 

ccm = SpotifyClientCredentials(client_id = cid, client_secret = secret)
sp = spotipy.Spotify(client_credentials_manager = ccm)

os.environ["SPOTIPY_CLIENT_ID"] = cid
os.environ["SPOTIPY_CLIENT_SECRET"] = secret
os.environ["SPOTIPY_REDIRECT_URI"] = "https://localhost:8080"

scope = 'user-library-read'
username = <YOUR USERNAME HERE>

 

token = spotipy.util.prompt_for_user_token(username, scope)

if token:
spotipy_obj = spotipy.Spotify(auth=token)
saved_tracks_resp = spotipy_obj.current_user_saved_tracks(limit=50)
else:
print('Couldn\'t get token for that username')

Do you have any tips for running it in google colab for SPOTIPY_REDIRECT_URI

To use Spotipy in Google Colab, you can follow the steps in this Stack Overflow answer: https://stackoverflow.com/a/68651136/7111585

i deployed my app using github and now this is not working, ive tried adding the github deployed link to the list or redirect uri but its still not working please help 😕 , in vscode if i use "const redirectUri = window.location.origin" then it works fine but this doesnt work after the app is deployed using github pages.
these are the Redirect URIs in my spotify app settings
http://127.0.0.1:5500

http://127.0.0.1:5500

http://localhost:8888/callback

http://127.0.0.1:5500/callback

http://localhost:5500/callback

 

I recommend you try to use 

http://google.com/callback/

 

Yes, mikazylay, but in combination with open_browser=False .

I am having same problem, in vscode redirectURL works fine but this doesnt works after the app is deployed using firebase. Did you find any solution??😓

You can use 

https://example.com

and will direct you to a page where you have to agree to some terms , once you click on agree it will redirect you to a page where you have to copy the url and past it in your console where asking you for a redirected url, and make sure you have all params as following  :

sp = spotipy.Spotify(
auth_manager=SpotifyOAuth(
client_id=client_id,
client_secret=client_secret,
redirect_uri="https://example.com",
scope="playlist-modify-private",
show_dialog=True,
cache_path="token.txt"
))

Where to get these redirect url.. ? 

 

Where I can get the redirect url.? 

 

Does it have to be local host only? I got the app working on local I want to deploy it using heroku but it doesn't let me. When I set redirect api to prod I get INVALID_CLIENT: Invalid redirect URI. Do I need to get my app reviewed by spotify first?

If you deploy to a online server, you'll need to change the redirect URI in your code to one point to the web address, and add it to the developers dashboard of your app (like you did when you were testing it on your computer).

Suggested posts