Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook SDK C# - get friends list

Using Facebook SDK (http://facebooksdk.codeplex.com/), you do something like this...

        string myAccessToken = "something";
        FacebookClient client = new FacebookClient(myAccessToken);
        IDictionary<string, object> friendData = (IDictionary<string, object>)client.Get("/me/friends");

Now how do you get the friends data out from the dictionary?

like image 774
001 Avatar asked Nov 29 '22 03:11

001


1 Answers

Your function for storing friends list from json data:

string myAccessToken = "something";         
FacebookClient client = new FacebookClient(myAccessToken);         

var friendListData = client.Get("/me/friends");
JObject friendListJson = JObject.Parse(friendListData.ToString()); 

List<FbUser> fbUsers = new List<FbUser>();
foreach (var friend in friendListJson["data"].Children())             
{   
    FbUser fbUser = new FbUser();
    fbUser.Id = friend["id"].ToString().Replace("\"", "");                 
    fbUser.Name = friend["name"].ToString().Replace("\"", "");                 
    fbUsers.Add(fbUser);
}

Class for facebook user

Class FbUser {
    String Id { set; get; }
    String Name { set; get; }
}
like image 99
asdf_enel_hak Avatar answered Dec 06 '22 06:12

asdf_enel_hak