They are saying in the AccessToken docu the following: "Native mobile applications using Facebook's SDKs will get long-lived access tokens, good for about 60 days. These tokens will be refreshed once per day when the person using your app makes a request to Facebook's servers."
Does it mean that only if the request to Facebook's servers is made from client Android app (I am not sure how to interpret the "... the person using your app ...") then the access token will be refreshed ?
In my app, I retrieve the access token using AccessToken.getCurrentAccessToken()
, send the access token to my server and the server makes the request to Facebook's servers with the aim to validate the received access token.
Will the access token be refreshed also in that case ? (in that case the server is doing the request to FB's servers and not directly "the person using my app")
AccessToken.getCurrentAccessToken()
in Android client returns the refreshed access token ?Thank you
EDIT: This may help the others to save time:
I found out that access token is under certain conditions automatically refreshed at initializing the FacebookSDK (Facebook docu doesn't clearly explain how the access token is refreshed - See my question above).
Please notice I am using FacebookSDK 4.0 for Android.
Follow the steps bellow:
FacebookSDK.sdkInitialize(Context, InitializeCallback)
if (AccessToken.getCurrentAccessToken() != null && Profile.getCurrentProfile() == null)
Profile.fetchProfileForCurrentAccessToken()
Utility.getGraphMeRequestWithCacheAsync()
GraphRequest graphRequest = getGraphMeRequestWithCache(accessToken);
graphRequest.setCallback(graphCallback);
graphRequest.executeAsync();
executeBatchAsync(GraphRequestBatch requests)
GraphRequestAsyncTask asyncTask = new GraphRequestAsyncTask(requests);
asyncTask.executeOnSettingsExecutor();
GraphRequestAsyncTask doInBackground()
method if (connection == null) {
return requests.executeAndWait();
} else {
return GraphRequest.executeConnectionAndWait(connection, requests);
}
For both cases the code will end up in this method:
public static List<GraphResponse> executeConnectionAndWait(
HttpURLConnection connection,
GraphRequestBatch requests)
AccessTokenManager.getInstance().extendAccessTokenIfNeeded();
line.
Which as the name suggest will extend your access token at most once per day.You can use the refreshCurrentAccessTokenAsync
method:
AccessToken.refreshCurrentAccessTokenAsync();
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