Facebook SDK C # - Get Friends List

Using the Facebook SDK ( http://facebooksdk.codeplex.com/ ), you are doing 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 friends data from the dictionary?

+4
source share
2 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; } } 
+21
source

I had the same problem and found a good solution. I did the same with linq, which reduced the amount of code. And in most cases less :)

 FacebookClient client = new FacebookClient(accessToken); dynamic friendListData = client.Get("/me/friends"); var result = (from i in (IEnumerable<dynamic>)friendListData.data select new { i.name, i.id }).ToList(); 
+1
source

Source: https://habr.com/ru/post/1387302/


All Articles