Using the BPC Facebook Utility

The Facebook utility allows you to connect to facebook, update your status, download your friends list, or publish a message on a friend’s wall.

Register your app with Facebook

The first thing you need to do before to use this control is to register your app with Facebook.

Go to this page : http://www.facebook.com/developers/, and click on the button “+ Set up new app”.

When you have filled several information about your app, you will get your application Id and secret token

image

You can now use the BPC Facebook control.

Connect to facebook in your Windows Phone app

The first thing to do is to add the facebook control to your page, and to set the app Id the the app secret :

<Phone:FacebookLoginControl x:Name="facebook" AppID="154224837975096" AppSecret="1c24f3ba7537d68efb218ee81bab232f" />

This control is collapsed by default, and will be automatically show a web browser and/or a progress bar when needed (on publication or on the friend list download).

You can now use this control in your code behind to connect to facebook :

private void Connect_Click(object sender, RoutedEventArgs e)
{
if (facebook.IsConnected)
MessageBox.Show("You are already connected");
else
{
facebook.ConnectionCompleted += new EventHandler(facebook_ConnectionCompleted);
facebook.Connect();
}
}

Download friend list

To download the friends list, you can call the method GetFriendsListAsync(). You will receive the list in the GetFriendsCompleted event as an array of FacebookUser.

private void loadFriends_Click(object sender, RoutedEventArgs e)
{
facebook.GetFriendsCompleted += new EventHandler<Bewise.Phone.GetFriendsEventArgs>(facebook_GetFriendsCompleted);
facebook.GetFriendsListAsync();
}

void facebook_GetFriendsCompleted(object sender, Bewise.Phone.GetFriendsEventArgs e)
{
friendList.ItemsSource = e.Friends;
}

Post a message

You can use one of these methods to post a message :

public void PostToMyWall(string message)
public void PostToMyWall(string caption, string description, string link, string message, string name, string pictureLink)
public void PostToFriendWall(String userId, String message)
public void PostToFriendWall(String userId, string caption, string description, string link, string message, string name, string pictureLink)

If you only want to update your status or send a message to a friend, you can only set the “message” param (and the userId if you post on a friend’s wall).
You can also send links, or message with description and picture.

Last edited Apr 15, 2011 at 2:00 PM by guillaumelac, version 2

Comments

shawchyn Apr 5, 2012 at 3:34 PM 
I'd 2 questions:
1: At the Facebook Developers App setting, at "Select how your app integrates with Facebook" which option should I select?
2: If I didn't select anything, and when run the connection, it shown the following error:
"An error occurred with XXXX, Please try again later. API Error Code: 11
API Error Description: This method is deprecated
Error message: Display=wap dialogs have been deprecared. You can temporarily enable them by disable the "july_2012" migration. They will stop working permanently on july 1, 2012"

does it mean this fbconnection is out of date?