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
- Add the Facebook developer application (https://www.facebook.com/developers/)
- Create new application
- Facebook provide you an API Key and a secret
- Edit your application to fill the Canvas Page URL and the CallBack Url
- Save your settings
Now that you have the API Key and a secret, you can develop your application:
- Install the Facebook developer toolkit (https://www.codeplex.com/FacebookToolkit)
- In Visual studio, check in the toolbar that you have facebook items (FaceBookService with facebook.dll, FriendMap,FriendList with Facebook.Controls.dll)
- Create a Windows Application
- Drag and drop FriendMap, FriendList and buttonControl on your windows form
- 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 :-)