使用facebook sdk(http://facebooksdk.codeplex.com/),您可以执行以下操作…
string myAccessToken = "something";
FacebookClient client = new FacebookClient(myAccessToken);
IDictionary<string, object> friendData = (IDictionary<string, object>)client.Get("/me/friends");
现在你如何从字典里找出朋友的资料?
最佳答案
从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; }
}