Spotipy how to authorize multiple users?

1.5k views Asked by At

I'm trying to create a webapp where the user authorizes their Spotify account so that the API has access, then the webapp creates a playlist based on their current music. I have it working for my own Spotify account, but when other people try using the app it doesn't ask them to log in (since it's already authorized with my account).

I think I'm using the wrong kind of token, but I'm very new to all of this and don't know what next steps to take. I read this post and see that something with a database will likely be necessary, and I also read the authorization code flow linked in that post. I haven't worked with any of that and the post/page aren't comprehensive enough for an absolute beginner like me, so I'm not sure where to start. Any help would be much appreciated. Here's the code I've written as a user authorization function:

def authenticate_user(username, scope, ID, SECRET, URI):
    '''
    Authenticates the user and creates a spotify object to interact with the API

    Returns: spotify object
    '''
    token = util.prompt_for_user_token(username, scope, ID, SECRET, URI)

    if token:
        sp = spotipy.Spotify(auth=token)

    else:
        print ("Can't get token for", username)
        return

    return sp

I'm guessing that after running it the first time and it properly connected with my own Spotify account, it already has that token and doesn't actually go through the authorization process for a new person trying the app because the token is already cached.

Again, any help or direction would be much appreciated.

1

There are 1 answers

0
Kwaku Biney On

Are you using the Spotify Authorization Flow? If you are, set show_dialog = True in token = util.prompt_for_user_token(username, scope, ID, SECRET, URI). Should work the way you want it to.

token = util.prompt_for_user_token(username, scope, ID, SECRET, URI, show_dialog = True)

Edit: Turns out this does not really work but follow the answer in Spotipy on Django authorization without copy-paste to console