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.
Related
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 am using C# winforms and C# Facebook SDK 6 to create an app that control my page and automate somethings.
In all posts in my page i put tags in the text to other pages so i want to know how to post a tag in my page posts using Facebook SDK and Facebook graph API.
I tried the message_tag parameter in different scenarios but it didn't work maybe i am using it wrong, the code below is one of the senarios :
dynamic postParameters = new ExpandoObject();
postParameters.message = textToPostTextBox.Text;
postParameters.message_tags = new { id = "page_to_tag_id", name = "PageName", type = "page", offset = 3, length = 4 };
dynamic result = fb.Post("my_page_id/feed", postParameters);
Notes : a tag to page is when you type "#" and write the page or person name.
Please help me i searched a lot online and i tried my self but it didn't work and sorry for my bad English.
Like said CBroe said, the bug got disabled because of too much abuse , But always there is a way ,
i know someone who did it, and this is how : he wrote a statue on facebook then he intercept the request sent from the browser and modify it to have a tag with customized text, I didn't try it but I know that it works
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.
Greetings and many thanks to the Stack Overflow community for all of the other awesome posts about the Facebook c# SDK. I have ran into a little challenge here and unfortunately I have not been able to find a previously posted solution.
How are you guys handling processing an nested JSON Object within a JSON response from the Facebook Open Graph API? For example, I am having some trouble getting to the nested venue JSON object that is returned when you retrieve a specific Facebook Event via the Open Graph: http://developers.facebook.com/docs/reference/api/event/
Here is some of the code that I am working with to provide more specific context:
var fbApp = new FacebookApp();
var auth = new CanvasAuthorizer(fbApp);
if(auth.IsAuthorized())
{
//output the FB user's Event
dynamic result = fbApp.Api("/" + EventID);
txtEventDesc.Text = result.name;
txtEventLoc.Text = result.location;
txtEventInfo.Text = result.description;
foreach (dynamic vi in VenueInfo.data)
{
//txtStreet.Text = vi.street;
}
}
...
So, how would you handle this embeded venue JSON object? Thanks in advance for taking the time to read my question and offer direction.
dynamic result = fbApp.Api("/" + EventID);
dynamic street = result.venue.street;
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.