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;
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 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!