2011-12-21 157 views

回答

21

您從JSON數據存儲好友列表功能:

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); 
} 

類爲Facebook用戶

Class FbUser { 
    String Id { set; get; } 
    String Name { set; get; } 
} 
+0

我們怎樣才能得到生日信息以及該回應?任何想法?我用這個,但沒有工作(「/我/朋友?fields = id,姓名,生日」); – achukrishnan 2014-07-18 05:08:27

1

正如我有同樣的問題,並一直在尋找一個很好的解決方案。我用linq做了同樣的事情,導致代碼少。並且大部分時間少於更多:)

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(); 
+0

在.net 4.5.1中不能編譯我 – Kiquenet 2014-11-18 21:28:42