Using the Starter Kit
By far the easiest way to start using the .NET Facebook API Client is to install the Starter Kit. The Starter Kit will install the Facebook Client binaries as well as a project template for Visual Studio that you can use to quickly get started developing your Facebook application.
Currently, the starter kit only has a template for ASP.NET MVC applications written in C#. We will be adding templates for WebForms and VB.NET at a later date. If you intend to use WebForms and/or VB.NET, you can still use the .NET Facebook API Client, but there are some additional steps you must follow first.
To use the starter kit:
- Download and run the appropriate installer from the latest release.
- Once it has completed, create a new project. In the "New Project" dialog, select “Visual C#” under “Project Types” on the left.
- Select the template, which will be listed under "My Templates" on the right.
- Enter a name for your project and click "OK".
- If you haven't already registered your application on Facebook, create one now. Otherwise, locate your API Key and Secret (see screenshot in the .NET Facebook API Client Wizard)
- Enter your API Key and Secret so that the configuration file can be populated.
- Click "Continue" to finish generating your project.
The following instructions are also available in the GetStarted text file included in the template:These instructions assume you have at least basic experience configuring IIS, any firewall you are running, and your router.
- Set up IIS to serve this application.
- Create a new web site pointed at this directory.
- Create IP/Hostname bindings if required.
- Ensure the service account and anonymous user account has proper access to this folder.
- Make sure your development computer is accessible from a public ip address. You may need to do one or more of the following:
- Open port 80 on your firewall
- Forward port 80 to this computer on your router
- Configure your Facebook application's Callback URL and Connect URL
- Go to www.facebook.com/developers/apps.php and select your app on the left.
- Click "Edit Settings" on the right.
- On the "Canvas" tab, set the Canvas Callback URL to your public IP address.
- See www.whatsmyip.org if you don't know your public IP.
- You can also use a domain name that is mapped to your IP address if you have one.
- Also on the "Canvas" tab, pick a Canvas Page URL.
- On the "Connect" tab, set the Connect URL to the same address as above.
- Click "Save"
- Compile your application.
- Start your application by going to your canvas url.
- Your canvas url will look like this: http://apps.facebook.com/yourappnamehere
Getting Started - IFrame applications
Much of the additional functionality provided by the .NET Facebook API Client Framework requires that your application is set up with
Facebook Connect. Please make sure you are properly integrated. Our demo site, for example, uses the following code to initialize the Facebook Clientside API:
<script type="text/javascript">
FB_RequireFeatures(["XFBML", "CanvasUtil", "Api"], function() {
FB.Facebook.init("<%= this.FbContext.ApiKey %>", "/xd_receiver.htm");
FB.XdComm.Server.init("/xd_receiver.htm");
FB.CanvasClient.startTimerToSizeToContent();
});
</script>
Getting Started - ASP.NET
There are a couple short steps that need to be accomplished before using the .NET Facebook API client in your ASP.NET application.
References
- Add references to Facebook.dll and Facebook.Web.dll
web.config
Facebook Configuration Section
- Add the following to the <configSections> element:
<section name="facebook" type="Facebook.Configuration.FacebookSection, Facebook" />
- Add the following configuration section to configure your Facebook Application:
<facebook>
<applications>
<add apiKey="YOUR_API_KEY_HERE" secret="YOUR_SECRET_HERE" />
</applications>
</facebook>
- You may add multiple API keys if your ASP.NET application will be handling requests for multiple Facebook applications.
FacebookHttpModule
- Configure the FacebookHttpModule in web.config:
<configuration>
<system.web>
<httpModules>
<add name="FacebookHttpModule" type="Facebook.Web.FacebookHttpModule, Facebook" />
</httpModules>
</system.web>
</configuration>
Control Inheritance
- It is recommended that ASP.NET pages and user controls inherit from the Facebook counterparts provided in the Facebook.Web.dll assembly:
- Page -> FacebookPage
- MasterPage -> FacebookMasterPage
- UserControl -> FacebookUserControl
Getting Started - ASP.NET MVC
The configuration for ASP.NET MVC applications is very similar to regular ASP.NET applications.
References
- Add references to Facebook.dll, Facebook.Web.dll and Facebook.Web.Mvc.dll
web.config
Facebook Configuration Section
- Add the following to the <configSections> element:
<section name="facebook" type="Facebook.Configuration.FacebookSection, Facebook" />
- Add the following configuration section to configure your Facebook Application:
<facebook>
<applications>
<add apiKey="YOUR_API_KEY_HERE" secret="YOUR_SECRET_HERE" />
</applications>
</facebook>
- You may add multiple API keys if your ASP.NET application will be handling requests for multiple Facebook applications.
FacebookMvcModule
- Configure the FacebookMvcModule in web.config:
<configuration>
<system.web>
<httpModules>
<add name="FacebookMvcModule" type="Facebook.Web.Mvc.FacebookMvcModule, Facebook.Web.Mvc" />
</httpModules>
</system.web>
</configuration>
Control Inheritance
- It is recommended that ASP.NET MVC views (master, partial and otherwise) inherit from the Facebook counterparts provided in the Facebook.Web.Mvc.dll assembly:
- ViewPage -> FacebookViewPage
- ViewMasterPage -> FacebookViewMasterPage
- ViewUserControl -> FacebookViewUserControl