python - Having trouble using cached tokens with Spotipy for Spotify? -


i'm trying use spotipy access user's spotify library running bit of trouble. background, i'm using flask, sqlalchemy, , flask-login.

i looked off of this tutorial on github started, 1 doesn't quite work me because if use cache, users can access playlist of user token cached, , since there cached token, user after first user can't login spotify. here initial setup:

sp_oauth = oauth2.spotifyoauth(os.environ['spotipy_client_id'],     os.environ['spotipy_client_secret'],     os.environ['spotipy_redirect_uri'],     scope="user-library-read") 

to solve this, first tried storing each user's access code in database (i'm using sqlalchemy well). looked (under method page spotipy redirects access code):

if request.args.get("code"):     dbsession.query(user).get(current_user.uid).addservice(             request.args["code"])     dbsession.commit() 

however, route meant return names of playlists user owns, want accessible without having go through spotify authorization url every time long user logged in. so, in case request.args["code"] null, try:

token_info = sp_oauth.get_access_token(dbsession.query(user)         .get(current_user.uid)         .getservice()) spotify = spotipy.spotify(token_info["access_token"]) 

then try access user using instance of spotify. however, using stored access code (unsurprisingly) gives me bad request error. i'm not sure getting new code, or should store don't need cache can still credentials access playlists. alternatively, there way can cache have users access tokens in cache?

thanks!


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -