Facebook, C# and ASP.NET MVC – Code samples for friends list, activities list and wall posts
A few weeks back I wrote about the official C# SDK from Facebook and provided some sample code demonstrating how to use it to get some basic information about the logged in user. Admittedly the initial sample asp.net mvc code was fairly simple in order for it to be straight forward and easy to understand. I’ve decided to expand a bit on the sample in order to demonstrate how to use the Open graph API to perform a few more interesting calls, notably:
- Post to a user’s wall
- Retrieve a list of the user’s friends
- Retrieve a list of the user’s activities
The original sample code demonstrated how to authenticate a user and make calls using both the official C# sdk and a home grown solution. I’ve kept that approach but have organized and refactored the samples a bit better to make it hopefully more clear. The new version of the sample code allows you to login/out to facebook only on the home page. Once logged in you can go to the ‘Official’ and ‘Custom’ tabs to view your friends, activities or to post a message to your wall. While the functionality is the same between the two tabs, the code behind them is different. I assume most people would use the official SDK but I provided an alternative just as a point of interest. OK, I was bored really, and just wanted to see how it could be done differently.
Facebook C# – Sample ASP.NET application and access tokens
Put together another quick sample app, this time for ASP.NET 4.0, instead of MVC.
I’ve also added an example of how to post to a user’s wall, using the Facebook C# SDK

Official Facebook C# SDK Released
Looks like a brand new SDK to play with for facebook. While they have other sdks for python, php, javascript, etc, this is their first official C# SDK. Previously the primary SDK that was available was the Facebook Developers Toolkit, which hasn’t been updated in some time (and hasn’t been updated to support the open graph api as far as I can tell).
You can grab the code from github at http://github.com/facebook/csharp-sdk.
Fixing Facebook IE problems
A friend of mine ran into this IE problem recently and it reminded me of one of the early snags I hit when developing a facebook application with the Open Graph API. IE is much more finicky about cross domain requests than other browsers, which can cause issues when authenticating with Facebook. The primary symptom of this problem is that a user can login to your site using the Facebook login button and firefox or chrome, but cannot log in via IE. The trick is that you need to also set the Base Domain field to handle multiple subdomains. So, if your Connect URL was http://www.somesite.com/, you’d set your Base Domain field to somesite.com.
Converting a Facebook Connect site to Open Graph step by step
A few weeks back I decided to upgrade one of my web apps to the Open Graph API. Previously it was running on Facebook Connect and using the Facebook Developers Toolkit on the backend. This still works fine, but it always felt like over kill. The simplicity of the new Open Graph api is compelling, and implementing it was pretty straight forward.

