mirror of
https://github.com/jwilsson/spotify-web-api-php.git
synced 2026-04-26 23:45:49 +03:00
[GH-ISSUE #262] Auto refresh option without refreshToken #192
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#192
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 @upgrader-dev on GitHub (Jun 2, 2023).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/262
Hello,
First of all thank you for your work:)
Initially I was not using the auto_refresh option provided by your code.
I'd like to use it but I can't understand how it could work without providing the refreshToken.
See SpotifyWebAPI.php line122 :
Maybe a solution would be to retrieve the refreshToken from the session object property or in argument of the function.
@jwilsson commented on GitHub (Jun 3, 2023):
Hey!
Thank you 😊
I don't know if you've seen the docs on how to set it auto refresh but basically what you need to do is to create a
Sessioninstance and provide a refresh token, and then pass thatSessioninstance toSpotifyWebAPI.What then happens "behind the scenes" is:
SpotifyWebAPI::sendRequest()(which you linked above),$session->refreshAccessToken()requests a new access token given the refresh token you passed it earlier and sets the new tokens on itself.SpotifyWebAPI::sendRequest()continues on to call itself with the same arguments, causingSpotifyWebAPI::authHeaders()to be called which will grab the new access token from itsSessioninstance and set that in the request headers.Hope this clarifies things 😄
@upgrader-dev commented on GitHub (Jun 3, 2023):
Hello,
Sorry I hadn’t find the docs about auto refresh, and I’m still a beginner :)
What you describe is what I was doing without success. I was getting an « no Token provided » error.
But finally I had found that passing the session object when making the instance of Api was a better way.
Thank you very much for this feature, it allows me to manage the entire Api in one service and only getting the api object on each page like magic :)
I close the issue
Regards
Benjamin Ghedini