Facebook fetcher C# console application

I am new at facebook sdk so asking very basic question. I need to fetch user information from Facebook in C# console application. I have created one Application in Facebook.com/developer and set its type to "Native/Desktop" and have its AppID as well as Secret Key. I have also downloaded Facebook C# SDK 5.4.1.

Now I am not sure, how to proceed, I tried to fetch all my feeds using following code.

FacebookClient client = new FacebookClient("AppID", "Secret Key");
var result = client.Get("me/feed");

But get exception " (OAuthException) An active access token must be used to query information about the current user ."

After some research I find out that I will have to get Access Token so I used following code to get access token

string url = "https://graph.facebook.com/oauth/access_token?client_id=APPID&client_secret=SECRETKEY&grant_type=client_credentials";
        WebRequest request = WebRequest.Create(url);
        WebResponse response = request.GetResponse();
        StreamReader reader = new StreamReader(response.GetResponseStream());
        string token = reader.ReadToEnd();

so I get response (in token) like this "access_token=322232329253232323|323233riZZZZZZZ_3p1BdHf3232332323k" So now I tried like this

FacebookClient client = new FacebookClient(token.Replace("access_token=", ""));
        var feeds = client.Get("me/feed");

But still get the exception " (OAuthException) An active access token must be used to query information about the current user.

Can anyone please guide me, how to proceed and fetch the information. Thanks in advance


If this is just a C# console application, the easiest way to access Facebook is probably via PowerShell and http://facebookpsmodule.codeplex.com. This will get you past the nitty-gritty of the Facebook API.

链接地址: http://www.djcxy.com/p/59932.html

上一篇: 使用单元连接将Android应用连接到套接字时出现问题

下一篇: Facebook fetcher C#控制台应用程序