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!
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 was using the Facebook Public API Feed for the longest time and since they deprecated it I've been trying to find a replacement method in C#.
I am able to get my page posts but any post that contains images I only get the message and no images. After spending the past weekend trying to find a way I am desperate to know if anyone has had any success in getting full page post content from the Facebook C# SDK library.
Here is what I have and it works for getting the posts but they do not contain any images.
var fb = new FacebookClient
{
AppId = ConfigurationManager.AppSettings.Get("FacebookAppID"),
AppSecret = ConfigurationManager.AppSettings.Get("FacebookAppSecret"),
AccessToken = ConfigurationManager.AppSettings.Get("FacebookAccessToken")
};
var pageFeed = string.Format("/v2.4/{0}/feed", _facebookPageId);
dynamic response = fb.Get(pageFeed);
Since the upgrade in Graph API v2.4. Only a limited set of data is sent via FB unless specifically requested. You should pass the fields parameter with the keyword of data which you would like to retrieve.
A list of keyword is available here
In your case, the request statement would be:
var pageFeed = string.Format("/v2.4/{0}/feed?fields=id,message,picture", _facebookPageId);
To get all pictures from a post: replace picture with attachments, as picture will return the very first picture linked to the post.
var pageFeed = string.Format("/v2.4/{0}/feed?fields=id,message,attachments", _facebookPageId);
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.
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 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.