I'm making an Android's app using Spotify SDK and Spotify Web Api Android from kaaes. What's the best way to refresh my access token? Since i need to keep the user logged.
I don't want that my app ask for log in everytime the users open the app.
How can I handle this ?
retrofit.RetrofitError: 401 Unauthorized
Login to Spotify failed because of invalid credentials
Thanks for your time and help! Regards.
To refresh the access token, select the Refresh access token API call within the Authorization folder of the Postman collection. Next, click the Send button to request a new access_token .
Access tokens issued from the Spotify account service has a lifetime of one hour. If a longer session is desired Spotify account service supports the OAuth Code grant flow.
Request Access Token If the user accepted your request, then your app is ready to exchange the authorization code for an Access Token. It can do this by making a POST request to the /api/token endpoint. This field must contain the value "authorization_code" . The authorization code returned from the previous request.
You need to use the Authorization Code flow from the Spotify Web API to obtain a refresh token that you can use to obtain a new access token when yours expires.
For that you need to have a web service with which you communicate from the Android app.
There is more information on this on https://github.com/spotify/android-sdk/issues/47
In case anyone else is having trouble with this issue, I made a gist you can use to stand up a free cloud function and handle this process:
https://gist.github.com/rldaulton/8b87216715d3cea828b5a9b27e300a3f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With