The prompt_for_user_token
function is a shorthand for some functionality provided by Spotipy. Here's the code of the function itself.
https://github.com/plamere/spotipy/blob/master/spotipy/util.py
[ -- snip -- ]
def prompt_for_user_token(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
'''
[ -- snip -- ]
cache_path = cache_path or ".cache-" + username
sp_oauth = oauth2.SpotifyOAuth(client_id, client_secret, redirect_uri,
scope=scope, cache_path=cache_path)
[ -- snip -- ]
token_info = sp_oauth.get_cached_token()
if not token_info:
print('''
User authentication requires interaction with your
web browser. Once you enter your credentials and
give authorization, you will be redirected to
a url. Paste that url you were directed to to
complete the authorization.
''')
auth_url = sp_oauth.get_authorize_url()
try:
import webbrowser
webbrowser.open(auth_url)
print("Opened %s in your browser" % auth_url)
except:
print("Please navigate here: %s" % auth_url)
[ -- snip -- ]
You can replicate the code and use auth_url
(for example) with popen
module and chrome.exe
, passing auth_url
as an argument.
TIP: Under windows cmd.exe /c start http://your.website/address
will forward the address to your current default browser. (as opposed to hardcoding firefox.exe
or chrome.exe
)