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 ?
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();
}
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);
http://www.codeproject.com/Articles/380635/Csharp-Application-Integration-with-Facebook-Twitt
I hope this will help you.!!!
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
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.
Related
I want to use C# to make friend with uid=14650247412 base on graph API
https://graph.facebook.com/me/friends/14650247412?access_token=EAAAxxx&method=post
But I don't know how to implement in C#, could you please help me do it?
I'm using Facebook from Nudget package
var client = new FacebookClient();
string uid = "14650247412";
dynamic parameters = {};
client.AccessToken = "EAAxxx";
var result = client.Post("https://graph.facebook.com/me/friends/" + uid , parameters);
the result is empty data
data = {}
Could you please show me how to do it? Thanks a lots
No. Adding friends is not possible through the API.
However, you can direct users to the webpage http://www.facebook.com/addfriend.php?id=[USER UID]
Where [USER UID] is a valid facebook user id.
Use WebBrowser control in a form dialog to achieve this.
I'm trying to retrieve data from 'Amazon Product Advertising API', and I see that I need to sign my request, and then the response is an XML document which should be parsed.
I wonder if there is any library which I can send my requests throught, and recieve the response back as an object.
If not, what should I do to convert those XML reponses to an object ? I've read about schemas, but where do I get those schemas from and where do I get from the defention for the response objects so I could define them my self.
Thanks alot!
You can use the following nuget package
PM> Install-Package Nager.AmazonProductAdvertising
Example:
var authentication = new AmazonAuthentication();
authentication.AccessKey = "accesskey";
authentication.SecretKey = "secretkey";
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.DE);
//Search
var result = await client.SearchItemsAsync("canon eos");
//Lookup
var result = await client.GetItemsAsync("B00BYPW00I");
There is a library that helps you sign requests AND process the responses by converting the XML into a relatively easy-to-use object. I've been using it for a few weeks now and wrote my own helper classes to really make querying the API fast and easy.
I wrote a demo console C# app where you can just plug in your Amazon credentials and start playing around here:
https://github.com/zoenberger/AmazonProductAdvertising
I also answered a similar question here:
https://stackoverflow.com/a/33617604/5543992
As per this link code from stack overflow i have try this code for getting
friendslist but after login i got this error "requires valid signature"
string APIKey = ConfigurationManager.AppSettings["API_Key"];
string APISecret = ConfigurationManager.AppSettings["API_Secret"];
Facebook.Session.ConnectSession connectsession = new Facebook.Session.ConnectSession(APIKey, APISecret);
Facebook.Rest.Api api = new Facebook.Rest.Api(connectsession);
var friends = api.Friends.GetLists();
foreach (var friend in friends)
{
System.Console.WriteLine(friend.name);
}
guide me to find out the solution
Thanks
ash
If you are starting with a new application, you should definitely use the Graph API and not the old Rest API. The Rest API has been deprecated for quite a while now and there is no guarantee how much longer Facebook will support it.
For an example on using the Graph API try http://csharpsdk.org/docs/web/getting-started
You can obtain the friends list by making a request to me/friends
You can test other requests using the Graph API explorer.
I am using Facebook Graph API and I wanted to put Like of any comment so I am doing like this.
FacebookGraphAPI obj = new FacebookGraphAPI(AccessToken);
obj.PutLike(item["id"].ToString().Replace("\"", ""));
It is not working even it will not give me error so how I can put the like.
Using the latest API, here's how to do a like (this assumes that there is a graph api like connection on the object being liked)
FacebookClient client = new FacebookClient(userAccessToken);
var result = client.Post(item["id"] + "/likes", null);
ProcessResult(result); // your code to determine how to handle the result being sent back from Facebook
The above code is from a current production working app of mine.
Happy coding!
I see there is a API call for Frienships/Show, but I am not sure how to parse the response to get the true/false.
Here is my code so far:
var twitter = FluentTwitter.CreateRequest()
.AuthenticateAs(_userName, _password)
.Friendships().Verify(_userNameToCheck)
.AsJson();
var response = twitter.Request();
Also, once authenticated, how to do set a user to follow you?
With TweetSharp you can access the friendships/exists API this way:
var twitter = FluentTwitter.CreateRequest()
.AuthenticateAs(_username, _password)
.Friendships()
.Verify(_username).IsFriendsWith(_userNameToCheck)
.AsJson();
There is no way to "set a user to follow you", they have to choose to follow you on their own.
There is an API for that listed in the API Wiki. The document can be found here. This will simply return true if it user A is following user B.
Here is a list of Libraries that probably support what your after.