Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to transparently renew the Facebook access token while processing a service method which uses Facebook API calls?
    text
    copied!<p>I have a WCF service which runs in IIS 7.5 and VS 2010. This service has some methods which internally use the <a href="http://facebooksdk.codeplex.com/" rel="noreferrer">Facebook C# SDK</a> (version 4.1, not latest) in order to perform some GET and POST from/to Facebook. Since Facebook will soon <a href="http://developers.facebook.com/roadmap/offline-access-removal/" rel="noreferrer">remove</a> the <code>offline_access</code> I have to handle the situation where an access token is expired.</p> <p>I have understood the way the authentication is performed (in order to get the code and after having the code to get the access token) in order to use the Graph API for getting Facebook information (as presented <a href="http://developers.facebook.com/attachment/serversideflow.png" rel="noreferrer">here</a>).</p> <p>I have two questions:<br></p> <ul> <li>When my service method is called and I retrieve the token of the appropriate user from my DB, is there a way to know if the access token is expired or not? <br>I have <a href="http://developers.facebook.com/docs/authentication/access-token-expiration/" rel="noreferrer">read</a> that when a Facebook API call is performed and the access token is expired then the following exception is thrown: <code>OAuthException</code>. But is there any better way to detect the expiration? I don't want to <br> <ol> <li>Call the Facebook API</li> <li>Handle the exception</li> <li>Renew the access token and finally </li> <li>Repeat the initial call with the new access token.<br></li> </ol></li> <li>Is it possible to renew the access token of the user transparently (store it also in the DB) and <em>continue</em> to handle the service method? In <a href="http://csharpsdk.org/docs/web/handling-expired-access-tokens" rel="noreferrer">this</a> resource, the important ("Renewing an Access Token") part is missing (declared as [todo])</li> </ul> <p>I would like to achieve the following scheme, in the implementation of the Service Method:<br></p> <pre><code>sc = SocialNetworkAccountDao.GetByUser(user) isExpired = call method to check if the sc.token is expired. if (isExpired) { newToken = call method for getting new access token sc.token = newToken; SocialNetworkAccount.Update(sc); } Facebook = new Facebook (sc.token) Facebook.Post( ..... ) -- </code></pre> <p>The process to communicate with the <code>QAuth</code> dialog is asynchronous (a redirect is performed), and the communication with access token url to get the access token this is performed synchronously.<br><br>Final Question:<br></p> <ul> <li>Is there a way the service method to wait for the new access token we retrieve from the request / callback with Facebook in order to continue later with the new access token?</li> </ul>
 

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