Facebook C# SDK - Windows 8 Metro Style Apps

(This feature requires Facebook C# SDK v5.5 at minimum)

Facebook C# SDK supports a wide variety of .NET framework ranging from .NET 3.5/4.0, Silverlight 4.0/5.0 and Windows Phone. Two months back we introduced support for Developer Preview version of .NET 4.5 with Facebook C# SDK v5.3 which allows you to take advantage of async/await and Task Parallel Library – TPL (You can read more on it here) and couple of weeks back we introduced support for TPL in Silverlight 5 with v5.4. With v5.5 we are introducing support for creating Windows Metro Style Apps. (Couple of weeks back I tweeted (@prabirshrestha) about porting SimpleJson (JSON library) and FluentHttp.Core (mockable HTTP web request wrapper for .NET) to WinRT which has made it a breeze to port Facebook C# SDK to WinRT.)

Since Windows 8 has not even hit BETA stage we will not be providing compiled binaries of Facebook.dll nor be distributing it via NuGet (package manager for .NET) anytime soon.

You will need a copy of Windows 8 Developer preview with Visual Studio 11 (express edition is supported) installed in order to compile Facebook.dll compatible with Windows 8 Metro apps. A new solution file called “Facebook-WinRT.sln” has been added in the Source folder. There is also a new sample “CS-WinRT.sln” which demonstrates authenticating the user and getting access token and then making Get/Post/Delete requests to Facebook server using async/await.

Here is a hello world example:

public async FacebookHelloWorld()
{
    try
    {
        var fb = new FacebookClient();
        dynamic result = await fb.GetTaskAsync("4");
        txtName.Text = result.name;
    }
    catch(FacebookApiException ex)
   {
       // catch facebook exceptions
   }
   catch(Exception ex)
   {
     // catch other non facebook exceptions: like no internet connection
   }
}

Happy New Year and have fun writing a Facebook Metro App and don’t forget to apply for Window 8 First Apps Content.