Click here to Skip to main content
15,036,891 members
Articles / Desktop Programming / WPF
Posted 15 Aug 2007


135 bookmarked

Creating a simple Facebook Application using WPF

Rate me:
Please Sign up or sign in to vote.
4.79/5 (36 votes)
7 Sep 20073 min read
The following article details how to create a very simple Facebook application using Facebook Platform & WPF
Screenshot - logo.jpg


Facebook is growing at an incredible pace (already 30 million users registered and doubling every 6 months). The new Facebook platform is an incredible software platform and can easily be extended using the provided SDK. The following Code Project article is an introduction into creating a very simple MSN Messenger or Yahoo! Messenger type application for Facebook.

In this first article, I will provide an overview of how to set up your Facebook application and write a very basic WPF application that connects to Facebook and populates your friends list.

Setting up Facebook

Visit the developer website.

Screenshot - screen1.jpg
  • Click on "Getting started"
  • Add Facebook Developer Application
  • Log into Facebook
  • Add Developer Application
  • Set up new application
  • Application Name: WPFB (Here you can choose any name as long as it doesn't contain the word Face
  • Click checkbox to agree with License Agreement and also expand the optional Fields
  • Change application type to Desktop (This is very important!)
  • Submit
Screenshot - screen2.jpg

Keep the API Key & Secret provided for use later.

Here is a discussion about whether it is legal to disclose the secret key of your application.

Creating a simple UI

Download the Facebook SDK binaries from here.

Create a WPF Application and add Image & ListBox Controls into a StackPanel.

    <Image x:Name="ProfilePicture"Stretch="None"HorizontalAlignment=
    <ListBox x:Name="FriendsListBox"/>

Add the following References to your project:

  • Facebook.dll
  • Facebook.Controls.dll
Screenshot - Refrences.jpg

Also add the following namespaces:

using Facebook.Components;               //FacebookService
using Facebook.Exceptions;
using Facebook.Entity;                   //User
using System.Windows.Media.Imaging;      //BitmapImage
using System.Collections.ObjectModel;    //Collection

Next, we have to create an instance of the Facebook service.

FacebookService service;

Now, we also need to setup the service with the API Key & Secret recorded earlier. I currently do this in the constructor of my Window.

service = new FacebookService();
service.IsDesktopApplication = true;
service.ApplicationKey = "1969299cd5b87513af9633715e0a63e9";
service.Secret = "5b3ff1b88c41eb117014f403e5cb9952";

Now we are ready to start getting information from Facebook. To download my profile picture from Facebook, add the following code to the SourceInitialized event of the Window.

User me = service.GetUserInfo();
if (me != null)
    ProfilePicture.Source = new BitmapImage(me.PictureSmallUrl);

This basically downloads the small profile picture from the specified URL. This is a good time to save and test your project. Once you have compiled and Run this application, the following logon screen gets displayed:

Screenshot - logon.jpg

I have also noticed that this currently doesn't work if you are behind an HTTP proxy server. I get a "The underlying connection was closed" exception. Future releases of Facebook SDK would hopefully include support for Proxy servers and allow you to rather log in by using a function to which you can supply a user name and password as opposed to showing the HTML based login screen...

Fill in your user name and password and now click on login. You should hopefully now see a Window with your profile picture displayed!

The next step is to populate the ListBox with all my friends. To get all your friends from Facebook, add the following code to the SourceInitialized Event:

Collection<User> friends = service.GetFriends();

Update the friend's ListBox with the following DataTemplate.

<ListBox x:Name="FriendsListBox" ItemsSource="{Binding}">
           <Image Source="{Binding Path=PictureSmallUrl}" />

The final step is to point the ListBox to the friends collection.

FriendsListBox.ItemsSource = friends;


As you can see, to setup and create a simple Facebook application is not very difficult. In the next couple of days, I will expand on this base and update the application. Planned future expansion will include:

  • Notifications from Facebook
  • More "Beautiful UI" that supports skinning, and
  • A send message feature once you double-clicked on a friend
Screenshot - done.jpg

With very little effort and quick beautifying touches, the final application looks like this! (I borrowed Sacha Barber's Glass Button effect for the friends icons)

Please comment on how I can improve my articles (since this is only my second) and also rate this article (even if you thought it was utterly useless!)



  • 13-Aug-2007 - First draft


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

South Africa South Africa
No Biography provided

Comments and Discussions

QuestionError Pin
Rajkumar Kale8-Jul-16 23:16
MemberRajkumar Kale8-Jul-16 23:16 
QuestionHeaders Problem? Pin
fr3ddy_110-Jul-12 1:27
Memberfr3ddy_110-Jul-12 1:27 
AnswerRe: Headers Problem? Pin
Shaharyar Ahmed20-Jan-13 20:01
MemberShaharyar Ahmed20-Jan-13 20:01 
Generalthank U Pin
Member 3940521-Dec-10 2:15
MemberMember 3940521-Dec-10 2:15 
GeneralWPF action Pin
Raymundo Ginez6-Dec-10 18:42
MemberRaymundo Ginez6-Dec-10 18:42 
GeneralSending messages to facebook in C# WPF app Pin
RoopaHP8-Jun-10 1:11
MemberRoopaHP8-Jun-10 1:11 
GeneralFacebook sdk 3.0 Pin
tocute30-Nov-09 14:58
Membertocute30-Nov-09 14:58 
GeneralRequested value 'Networking' was not found. Pin
leminh04889-Aug-09 22:32
Memberleminh04889-Aug-09 22:32 
GeneralError Debug Pin
Member 358600325-Feb-09 7:00
MemberMember 358600325-Feb-09 7:00 
GeneralCool Idea! Pin
Dieter Deysel22-Oct-08 9:18
MemberDieter Deysel22-Oct-08 9:18 
GeneralA cool, free WPF application for Facebook Pin
Dachuan25-Mar-08 21:57
MemberDachuan25-Mar-08 21:57 
GeneralShameless? Pin
indyfromoz27-Jun-08 14:28
Memberindyfromoz27-Jun-08 14:28 
GeneralDeveloper API Pin
Lawrence Botley7-Mar-08 1:23
MemberLawrence Botley7-Mar-08 1:23 
GeneralCool Pin
andalmeida8-Sep-07 2:38
Memberandalmeida8-Sep-07 2:38 
GeneralRe: Cool Pin
rudigrobler9-Sep-07 20:02
Memberrudigrobler9-Sep-07 20:02 
GeneralRe: Cool Pin
Virendrak29-Jun-09 21:50
MemberVirendrak29-Jun-09 21:50 
QuestionHow to get my site notifications in my facebook Inbox Pin
kesh_6_726-Aug-07 16:52
Memberkesh_6_726-Aug-07 16:52 
AnswerRe: How to get my site notifications in my facebook Inbox Pin
rudigrobler9-Sep-07 20:03
Memberrudigrobler9-Sep-07 20:03 
GeneralI did a Flickr type one using XLINQ Pin
Sacha Barber16-Aug-07 6:16
mvaSacha Barber16-Aug-07 6:16 
GeneralRe: I did a Flickr type one using XLINQ [modified] Pin
rudigrobler16-Aug-07 8:34
Memberrudigrobler16-Aug-07 8:34 
GeneralRe: I did a Flickr type one using XLINQ Pin
Sacha Barber16-Aug-07 9:41
mvaSacha Barber16-Aug-07 9:41 
GeneralSoruce Code for Article Pin
aman.tur16-Aug-07 2:59
professionalaman.tur16-Aug-07 2:59 
GeneralRe: Soruce Code for Article [modified] Pin
rudigrobler16-Aug-07 3:34
Memberrudigrobler16-Aug-07 3:34 
GeneralRe: Soruce Code for Article Pin
hackman3vilGuy16-Aug-07 6:32
Memberhackman3vilGuy16-Aug-07 6:32 
GeneralRe: Soruce Code for Article Pin
rudigrobler9-Sep-07 20:09
Memberrudigrobler9-Sep-07 20:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.