Update 2: The changes to the Facebook Toolkit library are now available for download from the Facebook Toolkit project page.
Update: I've just updated raya with the Facebook Connect changes. There were some initial problems with "invalid session key" issues but that has been resolved.
Over the weekend, I had look into integrating Facebook Connect into raya. The example given on the facebook developer wiki on how to do this is based on an example in PHP. The first lazy thing I did was to search some more and see if there were any .NET examples. Nope.
However, I found two .NET client libraries that would hopefully make my life easier; Facebook.NET and Facebook Developer Toolkit. At first glance, Facebook.NET seems targeted towards the use of facebook controls. Meanwhile, the FBT provides a more code intensive implementation. Some people seem to have gripes about the FBT. It seems to me that the FBT is closer to the facebook PHP client library. I'm guessing that if you used the FBTand followed any facebook PHP example, your ASP .NET implementation will be quite similar.
The question now is, what about ASP .NET MVC? No server-side controls on ASP .NET MVC ... how now brown cow?
Looking at the PHP example for Facebook Connect, I have managed to implement it using FDT. However, there were some minor additions that I had to add to the FDT to make this happen.I will attempt to explain how I did this in the following paragraphs. I will upload the code changes to support Facebook Connect onto raya. This will be Part 1 of an xx Part series as I don't know how many suitable size chunks I should split it to. Now on with the story ...
1. First, you will need add the facebook project under 'Source\Facebook' to your current solution. Normally, you just need to reference the DLL but we need to make some changes.
2. Reference the file Microsoft.Xml.Schema.Linq.dll from the 'Source\Facebook\bin\Release' folder. This is to get the cool LINQness from parsing an XML string using LINQ to XSD. Scott Hanselman has an article on this. Did I mention that it's an alpha release too?
3. Add the schema, facebook.xsd, from 'Source\Facebook\Schema' to 'C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas'. This is to get Visual Studio to recognise the FBML tag.
4. You will need to update your MasterPage's or ViewPage's <html> tag to get VS to recognise FBML tags
5 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://api.facebook.com/1.0/">
5. You will also need to reference the following script files
3 <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
4 type="text/javascript"></script>
5 <script src="/Scripts/fb/fbconnect.js" type="text/javascript"></script>
6. To display the login button, insert the following
27 <fb:login-button length="long" background="light" size="medium"
28 onlogin="facebook_onlogin_ready();"></fb:login-button>
7. In the same page, add the following javascript and replace APIKEY with your facebook api key that is given for the facebook application that you registered. You will need to register a facebook application to use Facebook Connect to get the API key. You will also need to set the Connect URL. Point this url to your site address. Using a localhost address is ok when debugging locally.
33 <script type="text/javascript">
34 FB_RequireFeatures(["XFBML"], function() {
35 FB.Facebook.init(
36 "<%= APIKEY %>", "/Content/xd_receiver.htm"); });
37 </script>
8. You will need the following additional files, which I have obtained from the PHP example of Facebook Connect.
xd_receiver.htm (322.00 bytes)
fbconnect.js (3.87 kb)
9. The changes to the FDT are also in the following files:
API.cs (24.23 kb)
connect.cs (3.06 kb)
users.cs (8.06 kb)
10. This will allow your site to show the Facebook connect button that will display a pop-up allowing your site users to log into their facebook account. From here, your site will be able to obtain the user's facebook session_key cookie.