[Python] Spotipy: Trying to get top artist based on Spotify username

Discussão em 'Python' iniciado por Stack, Março 11, 2025.

  1. Stack

    Stack Membro Participativo

    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

    Continue reading...

Compartilhe esta Página