authorize via an internal server instead of copy-paste

This commit is contained in:
David Todd 2018-04-24 16:32:08 -05:00
parent 4b03bbf48c
commit b57347b606
2 changed files with 9 additions and 2 deletions

View File

@ -16,6 +16,7 @@ show_all_playlist.py - Unlike the name suggests, I did not see all my playlists.
* Edit "set_env.sh" to configure your API ID, Secret, and redirect using the information from your previously created app
* Configure your environment by running `set_env.sh`
* Run `pip install -r requirements.txt` to install the required dependencies
* Optionally `git clone https://github.com/alopexc0de/spotipy.git` into venv/lib/python2.7/site-packages/ (replacing the pip-installed spotipy)
* Run any of the scripts to use them
## License: MIT

10
save_now_playing.py Normal file → Executable file
View File

@ -10,6 +10,7 @@
import sys
import time
import spotipy
import spotipy.util as util
from spotipy.client import SpotifyException
@ -42,10 +43,15 @@ def authorize_api(username, scope=None):
print "[%.2fs] Authorizing %s with this auth scope: %s" % \
(time.time()-start_time, username, scope)
# User Auth-Token - Achieved by running a webserver on localhost (might not be needed) as we just paste the URL here
# The access token appears to expire around 2000ish seconds of use.
# Rerunning this and retrieving the callback url (with new token) will allow the script to continue
token = util.prompt_for_user_token(username, scope)
# Use HttpSimpleServer based auth if available (using c0de's spotipy for example)
if hasattr(util, 'obtain_token_localhost'):
token = util.obtain_token_localhost(username, scope)
else:
token = util.prompt_for_user_token(username, scope)
if token:
# Authorize with the API