Viral
Viral

Reputation: 393

Facebook Retrive Data using Graph API using c#

i have created desktop Facebook application using c# .net. i want to retrieve users message,post and chat history. which is convenient way to retrieve users all information.i have started with Facebook Graph API but i am not getting any example.

can any one help me ?

Upvotes: 4

Views: 24263

Answers (5)

Greg R Taylor
Greg R Taylor

Reputation: 3676

A bit late to the party but anyway:

Add a reference to System.Net.Http and Newtonsoft.Json

string userToken = "theusertokentogiveyoumagicalpowers";

using (var client = new HttpClient())
{
    client.BaseAddress = new Uri("https://graph.facebook.com");

    HttpResponseMessage response = client.GetAsync($"me?fields=name,email&access_token={userToken}").Result;

    response.EnsureSuccessStatusCode();
    string result = response.Content.ReadAsStringAsync().Result;

    var jsonRes = JsonConvert.DeserializeObject<dynamic>(result);

    var email = jsonRes["email"].ToString();
}

Upvotes: 8

sommmen
sommmen

Reputation: 7628

From what i see the app now only uses webhooks to post data to a data endpoint (in your app) at which point you can parse and use this. (FQL is deprecated). This is used for things like messaging.

A get request can be send to the API to get info - like the amt. of likes on your page.

The docs of FB explain the string you have to send pretty nicely. Sending requests can be done with the webclient, or your own webrequests. https://msdn.microsoft.com/en-us/library/bay1b5dh(v=vs.110).aspx

Then once you have a string of the JSON formatted page you can parse this using JSON.NET library. It's available as a NUGEt package.

Upvotes: 0

Net
Net

Reputation: 51

Go to developer.facebook.com -> Tools & Support -> Select Graph API Explorer

Here U get FQL Query, Access Token

Then write code in C#.....

var client = new FacebookClient();
client.AccessToken = Your Access Token;

//show user's profile picture
dynamic me = client.Get("me?fields=picture");
pictureBoxProfile.Load(me.picture.data.url);

//show user's birthday
me = client.Get("me/?fields=birthday");
labelBirthday.Text = Convert.ToString(me.birthday);

Upvotes: 3

maxchirag
maxchirag

Reputation: 549

you can check the Graph explorer tool on Developer.facebook.com , go to Tools and select graph explorer, its a nice tool which gives you exact idea about what you can fetch by sending "GET" and "POST" method on FB Graph APis

Upvotes: 0

Related Questions