[GH-ISSUE #241] Two users, two tokens, same result sets #126

Closed
opened 2026-02-27 23:20:57 +03:00 by kerem · 1 comment
Owner

Originally created by @beekgeek on GitHub (Dec 31, 2017).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/241

I've got Spotipy running on a localhost. I've authenticated two different users and have confirmed their tokens are unique. When I run the following code to get currently playing information, I get the same results in spite of having different Spotify sessions running (different devices) for each of the users.

Testing further, this looks like a "current user" definition issue. Using the Spotipy "current_user()" method, I get the same username regardless of the token returned. Assuming log in / log out is even the right solution in this case not sure how I would implement log in this environment (running everything from command line). Shouldn't the authentication token be the basis for the results returned?

playback.py:

import sys
import spotipy
import spotipy.util as util

scope = 'user-library-read user-read-currently-playing user-read-playback-state'

if len(sys.argv) > 1:
    username = sys.argv[1]
    print username + ': '
else:
    print "Usage: %s username" % (sys.argv[0],)
    sys.exit()

token = util.prompt_for_user_token(username, scope)

if token:
    print "Token: "+ token + " // "
    sp = spotipy.Spotify(auth=token)
    results = sp.current_playback()
    isplaying = results['is_playing']
    print isplaying
    if isplaying:
        track = results['item']['name']
        artist = results['item']['artists'][0]['name']
        trackid = results['item']['id']
        device = results['device']['name']
        print track + " - " + trackid + " - " + artist + " - on " + device
else:
    print "Can't get token for", username
Originally created by @beekgeek on GitHub (Dec 31, 2017). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/241 I've got Spotipy running on a localhost. I've authenticated two different users and have confirmed their tokens are unique. When I run the following code to get currently playing information, I get the same results in spite of having different Spotify sessions running (different devices) for each of the users. Testing further, this looks like a "current user" definition issue. Using the Spotipy "current_user()" method, I get the same username regardless of the token returned. Assuming log in / log out is even the right solution in this case not sure how I would implement log in this environment (running everything from command line). Shouldn't the authentication token be the basis for the results returned? playback.py: ``` import sys import spotipy import spotipy.util as util scope = 'user-library-read user-read-currently-playing user-read-playback-state' if len(sys.argv) > 1: username = sys.argv[1] print username + ': ' else: print "Usage: %s username" % (sys.argv[0],) sys.exit() token = util.prompt_for_user_token(username, scope) if token: print "Token: "+ token + " // " sp = spotipy.Spotify(auth=token) results = sp.current_playback() isplaying = results['is_playing'] print isplaying if isplaying: track = results['item']['name'] artist = results['item']['artists'][0]['name'] trackid = results['item']['id'] device = results['device']['name'] print track + " - " + trackid + " - " + artist + " - on " + device else: print "Can't get token for", username ```
kerem closed this issue 2026-02-27 23:20:57 +03:00
Author
Owner

@beekgeek commented on GitHub (Jan 1, 2018):

Scope issue? I had a few different test scripts for my app with different scopes. I've updated them all to be consistent and now the issue seems to be resolved.

<!-- gh-comment-id:354633761 --> @beekgeek commented on GitHub (Jan 1, 2018): Scope issue? I had a few different test scripts for my app with different scopes. I've updated them all to be consistent and now the issue seems to be resolved.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#126
No description provided.