Rajat
Rajat

Reputation: 11127

Refreshing Access Token for Fitbit

I am integrating fitbit in my application and I don't want the user to redirect every time to SafariViewController to get the access token, for that i am storing the Access Token, but after 24 hours the Access Token is expiring.

In the API of fitbit Fitbit OAuth 2.0 there is a parameter expires_in which is used to define the expiration time of Access Token, In that parameter i am passing 31536000 for 1 year, but after that also the Access Token is expiring in 24 hours, and after that i have to redirect the user to SafariViewController.

So, is there any workaround so that i don't have to redirect user to SafariViewController, any methods through which i will refresh the token in background, something like that.

Any help would be appreciated.

Cheers !!!!!

Upvotes: 0

Views: 977

Answers (1)

Prakash P
Prakash P

Reputation: 340

You dont need to set any expires_in value to your access_token. The expire of access_token is checked in the fitbit server not in your server. So by setting the expires_in will not work. Instead you will get are refresh_token along with your acess_token after Fitbit authorization.By calling the

 $result=$fitbit_object->getRefreshtoken(YOUR_REFRSH_TOKEN);

The result will contains new access_token and refresh_token.Store/update them in you db. So when you want to use the aceess_token , you can use the new refresh_token to refresh your access_token . Its simply works for me.

Upvotes: 5

Related Questions