Skip to main content
April 18, 2013
Windows Phone Developer Blog

Facebook SDK for .NET – Featured in the Facebook Technology Partner program



This blog post was authored by Sanjeev Dwivedi, a developer evangelist for Microsoft working with Facebook.

– Adam


Today we are pleased to share with you that Facebook has announced the Facebook SDK for .NET as part of the Facebook Technology Partners program. This is a C#/XAML–based SDK that makes integrating your Windows Phone and Windows 8 style apps with Facebook a breeze. The SDK is an open-source project owned and released by the Outercurve Foundation. The Outercurve website for the SDK is http://facebooksdk.net, which hosts tutorials for both Windows 8 and Windows Phone, and has links to the GitHub repository where the source is hosted.

You can easily integrate the SDK into your project using NuGet, which automatically downloads and installs the SDK in your project. To do this, launch the Package Manager Console from the toolbar:
Tools > Library Package Manager > Package Manager Console

image

Install the Facebook NuGet package as part of your app by running the following command:

Install-Package Facebook

image

The Facebook SDK for .NET makes your life easier by providing two key functionalities:

  1. It takes away all of the complexity of logging on with Facebook. Based on the provided samples, all you need to do is use a bit of boilerplate code, add your Facebook app ID to the mix, and voila! You can have people logging on to your app with Facebook.
  2. It allows you to focus on your Facebook-related scenarios by abstracting away the low-level details such as HTTP connections and query parameters. This way you can plan and develop around Open Graph APIs and objects, which is where you want to spend your development resources.

An added benefit of using this SDK is that it provides very similar APIs on both the Windows Phone and the Windows 8 platforms, so code-sharing between the two platforms becomes very easy. Here is a snippet that showcases retrieval of a Friends list from Facebook on Windows Phone. As you can see in the code example, setting up the client and making the call to retrieve your Friends list requires just a few lines of code. The rest of the code is your logic around picking the data that is of interest to you.

Code Snippet
  1. // Instantiate the Facebook client
  2. FacebookClient fb = new FacebookClient(“<Supply Access Token here>”);
  3.  
  4. // Make the friends list Open Graph API request
  5. var friendsTaskResult = await fb.GetTaskAsync(“/me/friends”);
  6.  
  7. var result = (IDictionary<string, object>)friendsTaskResult;
  8. var data = (IEnumerable<object>)result[“data”];
  9. foreach (var item in data)
  10. {
  11.     var friend = (IDictionary<string, object>)item;
  12.     // Pick out the properties from the dictionary without the need for writing deserializing classes
  13.  
  14.     string name = (string)friend[“name”];
  15.     string id = (string)friend[“id”];
  16. }

You can find more details about the SDK on the Outercurve Foundation website: http://facebooksdk.net/docs/. You can also follow the development of the SDK at its Facebook page, report any issues on Github issue tracker, and ask any follow-up questions on the StackOverFlow forum. For details about how to obtain an Access Token, see the Authenticate section in the Windows Phone tutorial.


The offerings and resources presented may be relevant to developers. However, this post is for informational purposes only and Microsoft is providing this information “as is” with no warranties. Each contribution is licensed to you under an agreement by its provider, not Microsoft. It is your responsibility to evaluate if these resources are suitable for your usage.