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);
Related
I am developing a server application that should be able to react to the amount of likes for some of the posts in the user's feed.
I need to get post from users wall.
I'm using Facebook library version 6.4.2
I use the following code to get the posts:
var apiKey = ConfigurationManager.AppSettings["apiKey"];
var secret = ConfigurationManager.AppSettings["secret"];
var client = PostHandler.CreateFacebookClient(apiKey, secret);
var get = client.Get(string.Format("/{0}/feed", pageId));
and/or (both return the same info)
var token =ConfigurationManager.AppSettings["token"];
var get = client.Get(string.Format("/{0}/feed?access_token={1}", pageId, token));
The problem is that using the same set of permissions the json returned from the request above is different from the json returned from json returned from Graph API Explorer methog GET 100000481752436/feed
In my opinion the json returned from my request is missing some posts and the one from the Geaph API all contains the posts from my feed.
Could you please advice, what could I have missed ?
If you are missing some posts in the feed it is most likely that you'll have to check the permissions set again.
Based on the type of posts you are missing you maybe have to add the user_status, user_activities, user_friends, user_checkins or user_games_activity permissions. Please make sure that you're using the correct set of the permissions for your particular task.
If you'll specify the type of the posts you are missing you may get much more helpful answers.
I'm using Facebook .Net SDK(http://facebooksdk.net/) in my application. I need post an image to the wall of the user or his page.
I have this piece of code to try do this:
var postUrl = "<fbid>/feed";
var fbParameters = new Dictionary<string,object>();
fbParameters["message"] = postRequest.FacebookPostContent;
if (postRequest.MediaData != null && postRequest.MediaData.Length > 0)
{
var stream = new MemoryStream(postRequest.MediaData);
if (postRequest.ContentType.Equals("image/jpeg"))
{
postUrl = postUrl.Replace("/feed", "/photos");
fbParameters["picture"] = new FacebookMediaStream { ContentType = postRequest.ContentType, FileName = DateTime.UtcNow.ToString("ddmmyyyyhhmmss") + "-photo.jpeg" }.SetValue(stream);
}
}
if (!string.IsNullOrWhiteSpace(postRequest.FacebookPageId))
{
fbUserID = postRequest.FacebookPageId;
}
postUrl = postUrl.Replace("<fbid>", fbUserID);
var result = await facebookClient.PostTaskAsync(postUrl, fbParameters);
Look at my postUrl variable. I update the with the user ID in Facebook or the PageID if it is a page so the post should be properly posted in the right object. If there is some image to upload, so add it to the dictionary.
So, with it in mind, I have the following questions:
When the fbUserID is a user ID, the post happens perfectly, with the image and description but, when the ID is a PageID, only the description text is posted and image is just ignored(the user has the manage_page permissions so I dont think it is a permission issue). What I'm doing wrong that the image is not being posted to the page's wall?
If I want to post a video instead of a image, what should I change in this code?
Already saw many problems with other technologies here in SO but never a conclusive solution.
Thank you very much for the help, I really appreciate.
Regards,
Gutemberg
Got it!
Facebook creates a different section inside the page called Recent Posts by Others on Test Page where people allowed to post images will be there, like an attachment icon. In order to post directly to the page's feed/wall, all I need to do is instead of use the user access_token(even if user granted manage_pages permission) just use the access_token that comes in /me/accounts object for the respective page.
About the video post, I just set the ContentType to "video/mpeg" and at server instead of set picture parameter on dictionary, I've set the video field with the video byte[].
Thanks!
Regards,
As an alternative you could try the Share Content button shown in one of the answers here:
Upload video on Facebook using Graph REST API on Windows Phone 8.1
I found that to be easier than tackling authorization and manually posting.
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.
Is it possible to get all photos by a persons name through the Picasa Web Albums Data API?
All examples I can find, shows how to get photos by an albumid.
You can request a list of the most recent photos, with a very high value for max-results.
I'm not sure if you are using the .NET API Client Library, but if so, an example is here:
http://code.google.com/apis/picasaweb/docs/1.0/developers_guide_dotnet.html#ListRecentPhotos
Use query.NumberToRetrieve to set the value for max-results.
If you are not using the .NET Client Library, an example using HTTP protocol can be found here:
http://code.google.com/apis/picasaweb/docs/2.0/developers_guide_protocol.html#ListRecentPhotos
You can retrieve facial recognition data from the Picasa Web API through a (currently) undocumented API URL that is used by the Picasa desktop application. More info here:
http://klick.com/pharma/blog/2011/09/retrieving-face-tag-data-from-the-picasa-web-api/
by setting "default" that mean retrieving current user with that code you can retrive the user photos in specific album
PhotoQuery query = new PhotoQuery(PicasaQuery.CreatePicasaUri("default", albumId));
PicasaFeed feed = picasaService.Query(query);
foreach (var entry in feed.Entries)
{
PhotoAccessor photoAccessor = new PhotoAccessor((PicasaEntry)entry);
Photo photo = new Photo();
photo.Title = photoAccessor.PhotoTitle;
photo.Summary = photoAccessor.PhotoSummary;
photo.MediaUri = entry.Content.AbsoluteUri;
photo.Id = photoAccessor.Id;
photo.AlbumId = photoAccessor.AlbumId;
photos.Add(photo);
}
If you know the subjectid then using an RSS link you can get a feed of ALL images for that user regardless of albums. The link is:
http://picasaweb.google.com/data/feed/base/user/PICASA_USERNAME?alt=rss&kind=photo&subjectids=SOME_BIG_LONG_STRING_OF_CHARACTERS
Also, you can find the subjectids by going to each person on PWA and clicking the RSS link at the bottom of the page.
I am stil trying to find a way to get all subjectids without a manual lookup.
Source: http://credentiality2.blogspot.com/2010/02/picasa-gdata-api-and-face-recognition.html