Client Framework Concepts

The .NET Facebook API Client Framework is designed to mimic the design of the ASP.NET stack, providing a familiar structure to ASP.NET developers. Here is a summary of the major components of the framework:


The IFacebookContext takes the form of either FacebookDesktopContext or FacebookHttpContext. Pretty much all interaction with the Facebook API begins and using using the context - it is the single point through which all information is accessed.

Desktop Applications

To get an instance of FacebookDesktopContext:
var fbContext = FacebookDesktopContext.Current;
This will automatically initialize a FacebookDesktopContext with the API key and secret configured in the Facebook configuration section. If you have more than one application configured, it will use the first one listed.

Web Applications

The FacebookHttpContext is automatically initialized for you on each request. It is accessible as the FbContext property through FacebookMvcController, FacebookViewPage, FacebookViewMasterPage, and FacebookViewUserControl for ASP.NET MVC applications, and through FacebookPage, FacebookMasterPage, and FacebookUserControl for ASP.NET WebForms applications.
    public class DemoController : FacebookMvcController
        public ActionResult ShowMeTheApiKey()
            this.ViewData["ApiKey"] = this.FbContext.ApiKey;
            return View();


The methods exposed by the Facebook API are encapsulated by implementations of FacebookApiController. The controllers follow the same naming convention established by Facebook, using the prefix of the method name as the name for the controller. For example, any methods beginning with Auth. will be found in the AuthController class. All the controllers are exposed directly on whichever IFacebookContext implementation you are using.

A simple MVC controller that accesses the Application.getPublicInfo API method.
    public class DemoController : FacebookMvcController
        public ActionResult Application()
            var appInfo = this.FbContext.Application.GetPublicInfoByApiKey(this.FbContext.ApiKey);

            return View(appInfo.Value);


The FacebookRequest class is where the API method calls are generated. It is responsible for all aspects of preparing the API call request, including calculating the signature and generating the content that is POSTed to the Facebook API server. FacebookRequest is part of the internal framework, so you shouldn't need to interact with it directly.


The FacebookResponse class handles the processing of the responses of the Facebook API calls. It is capable of either processing a response immediately, or delaying the processing when the response is part of a Batch. FacebookResponse is part of the internal framework, so you shouldn't need to interact with it directly.


The IFacebookObject interface is used to provide access to the output of Facebook API methods that return complex types - types that aren't simple types like strings, DateTime values, and other numeric values.

See Also...

Last edited Feb 16, 2010 at 7:29 PM by DanielSchaffer, version 8


No comments yet.