spotipy-experiments/get_user_auth.py
David Todd (c0de) 7757235dbb Initial experiments complete
Here I learned how to authenticate my app over env, as well
as trigger an oauth login for the username specified

I created a small script that will write the now playing track info to a file
This is useful for keeping track of the song that is playing at all times
2018-01-27 22:01:42 -06:00

22 lines
525 B
Python

import sys
import spotipy
import spotipy.util as util
scope = 'user-library-read'
if len(sys.argv) > 1:
username = sys.argv[1]
else:
print "Usage: %s username" % (sys.argv[0],)
sys.exit()
token = util.prompt_for_user_token(username, scope)
if token:
sp = spotipy.Spotify(auth=token)
results = sp.current_user_saved_tracks()
for item in results['items']:
track = item['track']
print track['name'] + ' - ' + track['artists'][0]['name']
else:
print "Can't get token for", username