Merge pull request #169 from jessejoe/add_cache_path_param

Add cache_path as an argument to prompt_for_user_token()
This commit is contained in:
Paul Lamere 2017-09-17 11:17:37 -04:00 committed by GitHub
commit a99d20470f
1 changed files with 4 additions and 2 deletions

View File

@ -8,7 +8,7 @@ import spotipy
import webbrowser
def prompt_for_user_token(username, scope=None, client_id = None,
client_secret = None, redirect_uri = None):
client_secret = None, redirect_uri = None, cache_path = None):
''' prompts the user to login if necessary and returns
the user token suitable for use with the spotipy.Spotify
constructor
@ -20,6 +20,7 @@ def prompt_for_user_token(username, scope=None, client_id = None,
- client_id - the client id of your app
- client_secret - the client secret of your app
- redirect_uri - the redirect URI of your app
- cache_path - path to location to save tokens
'''
@ -46,8 +47,9 @@ def prompt_for_user_token(username, scope=None, client_id = None,
''')
raise spotipy.SpotifyException(550, -1, 'no credentials set')
cache_path = cache_path or ".cache-" + username
sp_oauth = oauth2.SpotifyOAuth(client_id, client_secret, redirect_uri,
scope=scope, cache_path=".cache-" + username )
scope=scope, cache_path=cache_path)
# try to get a valid token for this user, from the cache,
# if not in the cache, the create a new (this will send