Add Ons - DevSource
DevSource: Microsoft Developer Resource DevSource Home Sponsored by Microsoft Home Add Ons Architecture Languages Techniques Using VS Forums
Home arrow Add Ons arrow Page 3 - Using the Facebook API
Using the Facebook API
By Tim Stevens

Rate This Article: Add This Article To:

Using the Facebook API - ' Processing Info '
( Page 3 of 4 )

Querying and Processing Information

So, now that we've finally logged in, it's time to actually do something. Thankfully, the code to query for information about either the current user or their friends is fairly straightforward.

ADVERTISEMENT

Most hits against the Facebook server through the C# wrapper require the current user's UID, retrievable through the Api.Uid member (mind you, the various keys related to your application and session are also being provided transparently to you).

For example, to get metadata about the photo albums a user has created, the following code can be executed:

foreach (Album album in api.Albums(api.Uid).Enumerate())
{
  System.Console.WriteLine("Album Name: " + album.Name);
  System.Console.WriteLine("Album Description: " + 
    album.Description);
  System.Console.WriteLine("Album Location: " + album.Location);
  System.Console.WriteLine("Album Cover Photo URL: " 
   + album.Cover.Src);
}

However, in this application we focus on the information about the user himself, as well as his friends. The first step is to populate the drop-box in the upper-left of the application with a list of the user's friends, plus adding their own name. That code is contained in the listFriends() method:

private void listFriends()
{
    try
    {
	FriendCollection friends = api.Friends();
	ArrayList list = new ArrayList();

	DetailList deetList = new DetailList();
      deetList.Enable("pic");
      deetList.Enable("name");

	Person me = api.GetInfo(api.Uid, deetList);
	list.Add(me);

	//Only limited fields available here 
	int counter = 0;
	foreach (Person friend in friends.Enumerate())
	{    list.Add(friend);    }
	ComboBox.ObjectCollection coll 
        = new ComboBox.ObjectCollection(friendBox);
	friendBox.DisplayMember = "Name";
	friendBox.DataSource = list;
	friendBox.Enabled = true;
    }
    catch (Exception ex)
    { System.Console.WriteLine("Exception: " + ex); }
}

Basically, this method iterates the friends contained in an instance of FriendCollection and adds each Person inside to an instance of ArrayList, stopping to first retrieve and add the currently logged in user (a process that will be covered in more detail shortly). That ArrayList is then set to be the data source for the drop-box and the "Name" member variable is the value that is displayed in the list.

It's worth noting here that, while the Person class has a number of functions to return values like first and last name, birthday, and the like, most of their values are not retrieved through the Friends() function. To get those, we have to look into that GetInfo() function a little closer.



 
 
>>> More Add Ons Articles          >>> More By Tim Stevens
 



HD VOIP Has Arrived (with Tony Konstner)

Play Video >

All Videos >

Google and blonde jokes?

Read now >

Favorite books!

Read now >

View Now
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.