2

I'm learning the facebook api by writing simple console appliction. I'm trying to do simple things, with code examples I found on the web (and in stackoverflow).

The thing I'm trying to do, is getting all of MY friends list [name, id].

I run the code, but get #2500 error. Here is the code:

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

what am I missing in my code?

(sorry for my english)

Igy
  • 43,710
  • 8
  • 89
  • 115
samy
  • 1,949
  • 6
  • 39
  • 64
  • 1
    the [top answer here](http://stackoverflow.com/questions/9351241/need-help-on-oauthexception-code-2500) looks beneficial – Jonesopolis Aug 07 '13 at 20:27

1 Answers1

1
string myAccessToken = "something";         
FacebookClient client = new FacebookClient(myAccessToken); 

The myAccessToken is the User token you can get from here https://developers.facebook.com/tools/access_token/

instead of

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`
Adrian10 BEN
  • 1,283
  • 2
  • 11
  • 15