Before you start typing
Update-Package FacebookWeb here are some internals that you should be aware of.
appId : YOUR_APP_ID,
// other parameters,
oauth : true
fbsr_<app_id> when the user authorizes your app. Internally Facebook C# SDK checks for the new
fbsr_<app_id> cookie first, if found it creates the session from the specified cookie else reverts back to the old
fbs_<app_id> cookie. This way your existing code still works with oauth disabled, so no fear when updating your existing codes to v5.2.
Here is a big difference with the old and the new cookie. The new cookie doesn’t contain the access token but rather contains only code, which you can then exchange for access token. But Facebook C# SDK makes your life easier. Whenever you call the AccessToken property in the FacebookSession, the SDK is smart enough to retrieve the access token automatically for you if it hasn’t been set yet.
Here is a sample code on how it exchanges code the access token. Notice that it use FacebookApplication.Current to get the app_id and app_secret, so make sure to set the correct FacebookApplication either programmatically or using web.config file.
var oauthClient = new FacebookOAuthClient(FacebookApplication.Current);
var parameters = new Dictionary<string ,object>();
parameters["redirect_uri"] = null;
dynamic result = oauthClient.ExchangeCodeForAccessToken(code, parameters);
Make sure you set the redirect_uri as null in parameters and not oauthClient.RedirectUri = null; This is to maintain backward compatibility as redirect_uri is set to “http://www.facebook.com/connect/login_success.html” if oauthClient.RedirectUri is null.
FacebookSession is cached per request for optimal performance. This means it will call ExchangeCodeForAccessToken only once for the particular request as you can see the traffic in fiddler for the sample “CS-AspNetMvc3-JsSdk”.
public ActionResult Index()
var fb = new FacebookWebClient();
dynamic me = fb.Get("me");
ViewBag.me = me;
All the samples have been rewritten with detailed comments and instructions. This will help you get started. You can now click “build.cmd” from the source code to build the dll files and then run the sample solution files. (Please do not use build.cmd to build dll files and use it in production, the recommend way is still to use rake. build.cmd is meant for samples only without installing ruby and rake.)
Even though you may be a web developer or silverlight or windows phone 7 developer make sure to check out “CS-WinForms.sln” samples. It includes samples showing graph api, legacy rest api, fql, fql muti-query and batch requests in both synchronous and asynchronous way.
There are a bunch of new changes in v5.2. Make sure to read CHANGES.txt for more details before updating.