mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-01-04 22:32:40 +00:00
obtain_token_localhost() use same arguments as prompt_for_user_token()
This commit is contained in:
parent
7e38eddb49
commit
9c9ae86a23
@ -150,9 +150,49 @@ def start_local_http_server(port, handler=RequestHandler):
|
||||
return server
|
||||
|
||||
|
||||
def obtain_token_localhost(username, client_id, client_secret, redirect_uri, cache_path=None, scope=None):
|
||||
def obtain_token_localhost(username, scope=None, client_id=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
|
||||
|
||||
Parameters:
|
||||
|
||||
- username - the Spotify username
|
||||
- scope - the desired scope of the request
|
||||
- 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
|
||||
|
||||
'''
|
||||
|
||||
cache_path = cache_path or ".cache-" + username
|
||||
|
||||
if not client_id:
|
||||
client_id = os.getenv('SPOTIPY_CLIENT_ID')
|
||||
|
||||
if not client_secret:
|
||||
client_secret = os.getenv('SPOTIPY_CLIENT_SECRET')
|
||||
|
||||
if not redirect_uri:
|
||||
redirect_uri = os.getenv('SPOTIPY_REDIRECT_URI')
|
||||
|
||||
if not client_id:
|
||||
print('''
|
||||
You need to set your Spotify API credentials. You can do this by
|
||||
setting environment variables like so:
|
||||
|
||||
export SPOTIPY_CLIENT_ID='your-spotify-client-id'
|
||||
export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret'
|
||||
export SPOTIPY_REDIRECT_URI='your-app-redirect-url'
|
||||
|
||||
Get your credentials at
|
||||
https://developer.spotify.com/my-applications
|
||||
''')
|
||||
raise spotipy.SpotifyException(550, -1, 'no credentials set')
|
||||
|
||||
sp_oauth = oauth2.SpotifyOAuth(client_id, client_secret, redirect_uri, scope=scope, cache_path=cache_path)
|
||||
|
||||
token_info = sp_oauth.get_cached_token()
|
||||
|
Loading…
Reference in New Issue
Block a user