0

I am trying to get the top artists from a Spotify username (That is not my own) however I am getting INVALID_CLIENT: Invalid redirect URI page when doing so. What would be the right steps to implement this idea?

import spotipy
from spotipy.oauth2 import SpotifyOAuth
import spotipy.util as util

#Set up the Spotify API client
SPOTIFY_CLIENT_ID = "X"
SPOTIFY_SECRET = "X"
SCOPE = "user-top-read"
REDIRECT_URI = "http://localhost:8888/callback/"
USERNAME = "X"

token = util.prompt_for_user_token(USERNAME,scope=SCOPE,client_id=SPOTIFY_CLIENT_ID,client_secret=SPOTIFY_SECRET, redirect_uri=REDIRECT_URI)

if token:
    sp = spotipy.Spotify(auth=token)
    # Get user's top artists for spotify wrapped
    top_artists = sp.current_user_top_artists(limit=50, time_range="medium_term")
else:
    print("Can't get token for", USERNAME)

#Print the user's top artists
print("Your top artists from the past 6 months are:")
for artist in top_artists["items"]:
    print(artist["name"])

I have tried to log out of Spotify and log back in but it doesn't work in order to try and clear the cache. I have also included my redirect_uri into the Spotify dashboard

TheBeef
  • 15
  • 6
  • Does this answer your question? [Invalid redirect URI on spotify auth](https://stackoverflow.com/questions/32956443/invalid-redirect-uri-on-spotify-auth) – Trooper Z Dec 09 '22 at 21:14
  • This answers one of my questions. I am able to get the artists however it is linked to my own personal account. I want the top artists of another users @TrooperZ – TheBeef Dec 09 '22 at 21:19

1 Answers1

0

You will need to setup the callback URL in the settings for your app on the Developer Dashboard.

Simply log in, find your app and click "Edit Settings" in the top right section. Under redirect URIs you ad http://localhost:8888/callback and remember to click save in the bottom. This should resolve your issue.

iYasha
  • 61
  • 4
  • Hello thanks for the comment! I did do this however I am still unable to access the data of a specific user. It only gives me data for my own Spotify account – TheBeef Dec 09 '22 at 21:50
  • When you add Redirect URIs, you will click on "Add" button first and then on "Save" button ? And you still see "INVALID_CLIENT: Invalid redirect URI" on page? – iYasha Dec 09 '22 at 22:01
  • I think there is no way to get top artists from another account. If you check top_artists['href'] you'll see that request send to 'https://api.spotify.com/v1/me/top/artists?limit=50&offset=0' URL, which means you need to log in to this account first. – iYasha Dec 09 '22 at 22:12