[英]How To Get User Friends List Using Facebook C# SDK?
How can I retrieve User friends list using facebook c# sdk ? 如何使用facebook c#sdk检索用户朋友列表? And I need To know what permissions allow me to get that information.
我需要知道哪些权限允许我获取该信息。 Below is my own attempt, but it didn't work:
以下是我自己的尝试,但是没有用:
//retrieve all user friends ids & names in 2D array
public static string[,] getFriends(string accessToken)
{
string[,] friends;
FacebookClient fb = new FacebookClient(accessToken);
dynamic friend = fb.Get("me/friends");
int count = (int)friend.data.Count;
friends = new string[count, 2];
for (int i = 0; i <count; i++)
{
friends[i, 0] = friend.data[i].id;
friends[i, 1] = friend.data[i].name;
}//end for
return friends;
}//end get friends
First you need class to get all the data from result that give by Facebook in JSON format. 首先,您需要类来从Facebook以JSON格式给出的结果中获取所有数据。 Then you need gridview to display the data from class.
然后,您需要使用gridview来显示类中的数据。
Here the code to get your friends list: 这是获取您的朋友列表的代码:
public class MyFriends
{
public long uid { get; set; }
public string username { get; set; }
public string first_name { get; set; }
public string last_name { get; set; }
public long? friend_count { get; set; } //nullable
public string pic_big { get; set; }
public string birthday { get; set; }
public string birthday_date { get; set; }
public string contact_email { get; set; }
}
protected void friendsList()
{
var fb = new FacebookClient("YOUR TOKEN HERE");
var query = string.Format(@"SELECT uid, username, first_name, last_name, friend_count, pic_big, birthday, birthday_date, contact_email
FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())");
dynamic parameters = new ExpandoObject();
parameters.q = query;
dynamic results = fb.Get("/fql", parameters);
List<MyFriends> q = JsonConvert.DeserializeObject<List<MyFriends>>(results.data.ToString());
GridView1.DataSource = q;
GridView1.DataBind();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.