Search code examples
facebook-graph-apifacebook-android-sdkfacebook-access-tokenfacebook-authenticationfacebook-sdk-4.0

When to use Facebook AccessTokenTracker Android SDK?


I am interested how to handle AccessToken expiration when using the Facebook SDK for Android.
According to documentation of Access Tokens they are saying that developers don't need to worry about token expiration : "When using iOS, Android or our JavaScript SDK, the SDK will handle making sure that tokens are refreshed before they expire."
Assumption A : I assume that the quote above implies that AccessToken.getCurrentAccessToken() returns always non-expired access token, or is my assumption wrong ??
In the Facebook Login for Android documentation they are saying : "If you want your app to keep up with the current access token and profile, you can implement AccessTokenTracker and ProfileTracker classes."
My question is: Why should I implement AccessTokenTracker, if (according to 1 ) the SDK make sure that token are refreshed before they expire ?
If my assumption is correct, then the getCurrentAccessToken() returns always the non-expired token, so there should be no reason to track the AccessToken ?

Thank you for help!

EDIT
My assumption A is wrong, because according to this docu the person has to login again if the access token is invalid.


Solution

  • Typically you would use the AccessTokenTracker if you also save the access token elsewhere. Let's say that you keep the access token server side (so you can make requests offline), and the SDK updates the token with a refresh, in that case, you'll want to update the token on your server as well, this allows you to do that.

    Alternatively, if your app allows people to log off, or to switch to a different user, you can use the AccessTokenTracker and ProfileTracker to alert you when the user changes.