Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should really update the c#sdk to the latest version - they fix a lot of issues over time..</p> <p><strong>Renewing a token</strong><br/> This is our code that handles the renew call itself (c#sdk ver 6.0.16, but this should work on earlier versions as well):</p> <pre><code> /// &lt;summary&gt; /// Renews the token.. (offline deprecation) /// &lt;/summary&gt; /// &lt;param name="existingToken"&gt;The token to renew&lt;/param&gt; /// &lt;returns&gt;A new token (or the same as existing)&lt;/returns&gt; public static string RenewToken(string existingToken) { var fb = new FacebookClient(); dynamic result = fb.Get("oauth/access_token", new { client_id = FACEBOOK_APP_ID, client_secret = FACEBOOK_APP_SECRET, grant_type = "fb_exchange_token", fb_exchange_token = existingToken }); return result.access_token; } </code></pre> <p>Facebook says that the new token may be the same (but extended expiration) or a completely new one, so you should handle that in your logic if required.</p> <p>According to Facebook, you should call the renew up to once a day. (<a href="https://developers.facebook.com/roadmap/offline-access-removal/" rel="noreferrer">https://developers.facebook.com/roadmap/offline-access-removal/</a>)</p> <p><strike>We keep a time-stamp on when the last 'Facebook update' was done, and if that time is over 24h ago and the user is accessing our application, we go in the background and renew the token. (we also update other data, name, email and other things we need)</strike></p> <p>Apparently, it is not calling it up to once a day, but calling it once per token.</p> <p>Facebook will not let you renew a longed-live token. See 'Scenario 4:' at the <a href="https://developers.facebook.com/roadmap/offline-access-removal/" rel="noreferrer">offline access removal page</a></p> <p>To clarify: short-lived tokens come from clients, long-lived tokens come from server-side.</p> <p>In short, when a user access your app, use the SDK of the client to get a new short-lived token send it to the server, and extend it with your server to make it a long-lived and store that, so you get 60 days from that point.</p> <p><strong>Handling the Expired time</strong><br/> In our current usage, we were not required to keep the track of expire time, as all access starts with a client that checks that, but in the same the code access <code>result.access_token</code> it can access <code>result.expires</code> which returns the number of seconds remaining on that newly acquired token (should be close to 5 mil => 60 days)).</p> <p>In any case, I am not sure there is a way to get the expire time from a token without making another call to the auth process. I know that the <a href="https://developers.facebook.com/tools/debug/access_token" rel="noreferrer">Facebook Debugger</a> returns this, but that does not really helps..</p> <p><strong>Renewing an invalid token</strong><br/> <em>This will not work</em>, you will get any of the errors as explained <a href="https://developers.facebook.com/blog/post/2011/05/13/how-to--handle-expired-access-tokens/" rel="noreferrer">here</a> when trying to renew an expired/invalid token.<br/> Remember to call the renew before it expires and remember that when you call renew on an expired (or any other kind of invalid) you will get an error and need to handle it (we handle it outside the code I pasted).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload