2

我正在通过编写简单的控制台应用程序来学习 facebook api。我正在尝试使用我在网络上(以及在 stackoverflow 中)找到的代码示例来做简单的事情。

我正在尝试做的事情是获取我所有的朋友列表 [name, id]。

我运行代码,但得到 #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();
        }
    }
}

我的代码中缺少什么?

(对不起我的英语不好)

4

1 回答 1

1
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`
于 2013-08-14T11:34:39.517 回答