This project is read-only.

GetFriends example code

Sep 25, 2011 at 7:22 AM

What do I get in the IList? Friend userids?

Can some one post me a code example of fetch names of the logged in users?

Oct 23, 2011 at 8:06 AM

The IList is a collection of ID/Name pairs, as NameIDPair objects.  So once you have that just loop through it:

IList<NameIDPair> friends = FB.User.GetFriends(userID , Api.AccessToken);
foreach ( var pair in friends )
{
    FB.User friend = new FB.User(pair.ID , Api.AccessToken);
// assume we're building a HTML table
    string row = "<tr>";
    row += "<td>" + friend.ID + "</td>";
    row += "<td>" + friend.Name + "</td>";
    row += "<td>" + ( friend.Birthday.HasValue ?
        friend.Birthday.Value.ToShortDateString() + " " : "&nbsp;" ) + "</td>";
    row += "<td>" + friend.Gender + "</td>";
    row += "<td>" + friend.Username + "</td>";
    row += "</tr>";
// add row to table
}
// render table
I just published another discussion thread here that documents how to get better performance when processing a lot of friend records, but for individuals the above will work.