title: Facebook: refresh AccessToken on Android
body: <p>They are saying in the <a href="https://developers.facebook.com/docs/facebook-login/access-tokens#extending" rel="noreferrer">AccessToken docu</a> 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."<br>
  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 ?<br>
  In my app, I retrieve the access token using <code>AccessToken.getCurrentAccessToken()</code>, 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.<br>
  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")  </p>
  
  <ul>
  <li>If yes, How does the Facebook SDK in the Android client app knows that my server made the request to Facebook's servers ? Does the<code>AccessToken.getCurrentAccessToken()</code> in Android client returns the refreshed access token ?</li>
  </ul>
  
  <p>Thank you</p>
  
  <p><strong>EDIT</strong>: 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).<br>
  Please notice I am using FacebookSDK 4.0 for Android.<br>
  Follow the steps bellow:  </p>
  
  <ol>
  <li><p><code>FacebookSDK.sdkInitialize(Context, InitializeCallback)</code>  </p>
  
  <p><code>if (AccessToken.getCurrentAccessToken() != null &amp;&amp;                       Profile.getCurrentProfile() == null)</code></p></li>
  <li><p><code>Profile.fetchProfileForCurrentAccessToken()</code></p></li>
  <li><p><code>Utility.getGraphMeRequestWithCacheAsync()</code>  </p>
  
  <p><code>GraphRequest graphRequest = getGraphMeRequestWithCache(accessToken); 
  graphRequest.setCallback(graphCallback);
  graphRequest.executeAsync();</code></p></li>
  <li>... <code>executeBatchAsync(GraphRequestBatch requests)</code><br>
  <code>GraphRequestAsyncTask asyncTask = new GraphRequestAsyncTask(requests);
  asyncTask.executeOnSettingsExecutor();</code></li>
  <li>See <code>GraphRequestAsyncTask doInBackground()</code> method  </li>
  </ol>
  
  <p><code>if (connection == null) {
       return requests.executeAndWait();
   } else {
      return GraphRequest.executeConnectionAndWait(connection, requests);
   }</code></p>
  
  <p>For both cases the code will end up in this method:  </p>
  
  <pre><code>public static List&lt;GraphResponse&gt; executeConnectionAndWait(
              HttpURLConnection connection,
              GraphRequestBatch requests)
  </code></pre>
  
  <ol start="6">
  <li>Notice <code>AccessTokenManager.getInstance().extendAccessTokenIfNeeded();</code> line.
  Which as the name suggest will extend your access token at most once per day.</li>
  </ol>