从脸书上找我的朋友
本文关键字:我的朋友 | 更新日期: 2023-09-27 18:26:51
我正在通过编写简单的控制台应用程序来学习facebookapi。我正在尝试做一些简单的事情,使用我在网上(以及stackoverflow中)找到的代码示例。
我想做的是,获取我所有的朋友列表[姓名,身份证]。
我运行了代码,但得到了#2500错误。这是代码:
class Program
{
static void Main(string[] args)
{
FacebookClient fbClient = new FacebookClient();
dynamic result = fbClient.Get("oauth/access_token", new
{
client_id = <REMOVED APP ID>,
client_secret = "<REMOVED APP SECRET>",
grant_type = "client_credentials"
});
fbClient.AccessToken = result.access_token;
var friendListData = fbClient.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);
}
foreach (var item in fbUsers)
{
Console.WriteLine(item);
Console.WriteLine();
}
}
}
我的代码中缺少什么?
(对不起我的英语)
string myAccessToken = "something";
FacebookClient client = new FacebookClient(myAccessToken);
myAccessToken是您可以从这里获得的用户令牌https://developers.facebook.com/tools/access_token/
而不是
FacebookClient fbClient = new FacebookClient();
dynamic result = fbClient.Get("oauth/access_token", new
{
client_id = <REMOVED APP ID>,
client_secret = "<REMOVED APP SECRET>",
grant_type = "client_credentials"
});
fbClient.AccessToken = result.access_token;`enter code here`