Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh Access Token on Spotify SDK for Android?

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.

like image 848
Maverick.pe Avatar asked May 06 '15 18:05

Maverick.pe


People also ask

How do I refresh my access token?

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 .

How long do Spotify refresh tokens?

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.

How do I use Spotify API access token?

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.


2 Answers

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

like image 80
José M. Pérez Avatar answered Oct 16 '22 06:10

José M. Pérez


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

like image 25
Ryan Daulton Avatar answered Oct 16 '22 05:10

Ryan Daulton