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:
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.