mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-27 00:25:54 +03:00
[GH-ISSUE #733] Refresh user token periodically #442
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#442
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @fluffy-cakes on GitHub (Oct 7, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/733
Hi, I have searched the FAQ and Issues, but still can't find, or seem to understand, how to implement an automatic token refresh without having to close and re-open the app/script. My current design is a Spotify voting web app that runs in Flask, allowing users to vote up/down the song to keep/skip playing it.
I currently use this as authorisation, as I believe that this method is required to poll the users 'currently playing' tracks.
Later on I use
sp.current_user_playing_track()to get the track and to grab some values from the output. This happens every second, updating the web app with the current track details. Within the hour, obviously, the cached token expires, and I will need to stop my running app and start it again. Not currently ideal, as I'm going to be using this over the space of 2-3 hours in a session.I did think about running a background task to spin of a subprocess just to log in, hopefully updating the token as it does. But this doesn't seem to work either:
I am not new to Python, but I am also not anything great. Can anyone please direct me on how I can achieve the above?
@stephanebruckert commented on GitHub (Oct 7, 2021):
prompt_for_user_tokenis deprecated, please avoid using it as it was only there to quickly help running an app and I'm not sure it refreshes the token for you. The new way to do it is displayed in the README.Also the FAQ specifically mentions building an API with Flask https://github.com/plamere/spotipy/blob/master/FAQ.md#how-to-use-spotipy-in-an-api, in which the token refresh is handled automatically. Did you have a look at it? Let us know what blocks there.
@fluffy-cakes commented on GitHub (Oct 7, 2021):
Cheers for the prompt reply, I am looking into that flask example and then the auth handling. I'll reply back or close once I understand them.
@fluffy-cakes commented on GitHub (Oct 7, 2021):
@stephanebruckert ; cheers for that. from those examples i was able to get working what i wanted 👍🏼