mirror of
https://github.com/jwilsson/spotify-web-api-php.git
synced 2026-04-27 07:55:49 +03:00
[GH-ISSUE #72] Unsure on how to use the refresh token #38
Labels
No labels
bug
docs
enhancement
enhancement
enhancement
feedback wanted
good first issue
help wanted
help wanted
help wanted
invalid
pull-request
question
question
upstream
upstream
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotify-web-api-php#38
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 @Cannonb4ll on GitHub (Mar 23, 2017).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/72
Currently creating an app where users basically login, and after they login they can hookup their spotify account to their account in the app im creating.
I get a accessToken and refreshToken, but what is the structural way to use this? I now have after a few minutes/hours that the accesstoken gets expired (which I save in my database).
How do I extend the accestoken with the refreshtoken, and when?
@jwilsson commented on GitHub (Mar 24, 2017):
When the access token expires (either by you catching the error from Spotify or checking it against your database) you use the
Session::refreshAccessToken()to request new tokens, which you then save in the database.There's some more info and examples here: https://jwilsson.github.io/spotify-web-api-php/authorization.html#step-2
@Cannonb4ll commented on GitHub (Mar 24, 2017):
Thank you. Would it be bad practise to execute that method each time the user logs in?
@jwilsson commented on GitHub (Mar 24, 2017):
Hmm, I think the best way is to only request it when needed. I don't know if Spotify might start blocking your app or something if you request tokens too often.
@Cannonb4ll commented on GitHub (Mar 24, 2017):
Alright, with a try-catch?
@jwilsson commented on GitHub (Mar 24, 2017):
Yes, exactly! And when it fails, you refresh the token (if it's that kind of error).
@Cannonb4ll commented on GitHub (Mar 24, 2017):
Alright I think I get that! So sorta like this:
@jwilsson commented on GitHub (Mar 24, 2017):
Yeah, I would check the code and message of the
Exceptiontoo. Just to see if it's an expired access token error. I don't know the exakt message to look for though, but the status code should be401.@Cannonb4ll commented on GitHub (Mar 24, 2017):
Thank you for your help, I will do that. Solved! :)