Create your own desktop Facebook application in C#

In France, FaceBook is coming since a few months … and it makes a lot of noise. What is cool with this social network, it’s that we can develop customs applications.

I decided to explain steps to create a windows form which get facebook information.

First of all you have to create a FaceBook application in facebook:

Subscribe to Facebook

  1. Add the Facebook developer application (https://www.facebook.com/developers/)
  2. Create new application
    • Facebook provide you an API Key and a secret
  3. Edit your application to fill the Canvas Page URL and the CallBack Url
  4. Save your settings

Now that you have the API Key and a secret, you can develop your application:

  1. Install the Facebook developer toolkit (https://www.codeplex.com/FacebookToolkit)
  2. In Visual studio, check in the toolbar that you have facebook items (FaceBookService with facebook.dll, FriendMap,FriendList with Facebook.Controls.dll)
  3. Create a Windows Application
  4. Drag and drop FriendMap, FriendList and buttonControl on your windows form
  5. Add the following Code:

 

public partial class Form1 : Form
{

public Facebook.Components.FacebookService _fbService;

public Form1()
{
       InitializeComponent();
       _fbService = new Facebook.Components.FacebookService();
       _fbService.ApplicationKey = "ApplicationKey";
       _fbService.Secret = "Secret";
       _fbService.IsDesktopApplication = true;
}

private void button1_Click(object sender, EventArgs e)
{
      Collection<User> users = _fbService.GetFriends();
      friendMap1.Friends = users;
     friendList1.Friends = users;
}

}

 

F5 and enjoy :-)