2011-12-21 17 views
4

を取得し、あなたがこのような何かを...FacebookのSDK C# - FacebookのSDK(<a href="http://facebooksdk.codeplex.com/" rel="nofollow">http://facebooksdk.codeplex.com/</a>)を使用して、フレンドリスト

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

今、あなたは辞書からの友人のデータを得るのですか?私は同じ問題を持っていたし、素敵な解決策を探していたとして、Facebookのユーザー

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

答えて

21

あなたの機能。私は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

どのように私たちはその応答と一緒に誕生日の情報を得ることができますか?私はこれを使用しましたが、仕事はしませんでした( "/ me/friends?fields = id、name、birthday")。 – achukrishnan

1

ため

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

クラス:JSONデータからフレンドリストを格納するための

+0

.net 4.5.1ではコンパイルされません – Kiquenet

関連する問題