Getting Facebook comments "From" field using Graph API [duplicate] - facebook

Recently, when using the /feed Facebook Graph API method, it has stopped returning the From field. This field typically contains the Id and Name of the author of the Facebook Post in question.
The URL I'm hitting is https://graph.facebook.com/{id}/feed?fields={my-fields-here}&access_token={token}
From what I can tell, the From field still exists within the API: If I try https://graph.facebook.com/{id}/feed?fields=id,from&access_token={token} I get a list of IDs (no Froms though), without errors.
However, if I try a deliberately-invalid field name, such as https://graph.facebook.com/{id}/feed?fields=id,doesnotexist&access_token={token} then I get an error response of (#100) Unknown fields: doesnotexist.
So the From field still exists as far as the Facebook Graph API is concerned. It's just no longer being returned. Did something change recently? The From field is also still listed as the list of fields over on their documentation. As far as the data itself goes, posts dating months back also no longer have From, so it's not a case of "newer posts in the feed lack the field, but older posts do either."
I'm at a loss! If anyone could lend a hand, I'd appreciate it.

It is only included if you use a Page Token. v2.11 of the Graph API (90-Day Breaking Changes):
/page/* — User information will not be included in GET responses for
any objects owned by (on) a Page unless the request is made with a
Page access token. This affects all nodes and edges that return data
for objects owned by a Page.
Source: https://developers.facebook.com/docs/graph-api/changelog/version2.11
...or in the link of your question:
Any valid access token can read posts on a public Page, but responses
will not include User information.
A Page access token can read all Posts posted to or posted by that Page, and responses will include User information.

Related

Get Share Count of Public Video with FB API v2.5

The Short Version:
"I can visit the public page without being logged into Facebook and see underneath the post is says "2155 shares" I would like to know how to access that number through the API"
The Details:
I'm trying to use the newest version (v2.5) of the graph HTTP API to determine the total share count for a public video. The problem is FB seems to have changed the API enough that older posts on SO no longer answer this question.
Looking at the Graph API Documentation it appears that video nodes now have the "sharedposts" edge. However, calling this route with summary=true only returns a few of the shares and no value for a total count. This returns counts for comments and likes so I'm not using the endpoints incorrectly or messing up my authorization.
I've also tried to use the URL Node but this doesn't seem to do much with links inside of Facebook. I simply get a JSON response with an 'id' field with the same url I supplied as a request parameter. Seems like this route is meant to be used for links to content outside of Facebook.
I've tried the above methods with multiple videos on multiple public pages so I don't think it is due to the group owners restricting access, unless this is the new default.
It seems arbitrary that I would be allowed access to total counts for comments and likes, but not shares. Is there some legacy way to do this or am I out of luck for now?
You should query the Post element containing the Video element.
Each video posted is also contained in a post element.
The post id is then composed of the video id prepended with the posting entities id (user, page etc'), separated with an underscore.
It then looks like: user-id_video-id.
Then using the Graph API to get the share count of a post is straightforward:
GET /v2.5/{post-id}?fields=shares
Example
Lets take a video from the BBC page:
https://www.facebook.com/bbcnews/videos/10153524838517217/
(Please tell me if the link is broken. I'll switch it to something newer :))
Video id : 10153524838517217
Page id (see below): 228735667216
--> Post id: 228735667216_10153524838517217
And the request would be:
GET /v2.5/228735667216_10153524838517217?fields=shares
(open in the Graph API explorer)
Page id
to get the page id, you could query the video element for the from field.
GET /v2.5/10153524838517217?fields=from

Facebook Insights - Post Details

In the "Posts" section of Facebook Insights, you can click on your latest posts and get detailed information about them:
I'm trying to recreate this data in a web application, using the Facebook SDK for .NET. I have found most of these numbers through Facebook's Graph API, e.g:
.../v2.3/(page-id_post-id)/insights/post_impressions_unique/lifetime
.../v2.3/(page-id_post-id)/insights/post_stories_by_action_type/lifetime
.../v2.3/(page-id_post-id)/insights/post_consumptions_by_type/lifetime
.../v2.3/(page-id_post-id)/insights/post_negative_feedback_by_type/lifetime
...except the post content and the numbers marked in red. Using Fiddler, it looks like Facebook fetches these values from a URL outside the Graph API:
https://www.facebook.com/ajax/pages/insights/view_story/...
However, that URL is only accessible if you're logged in to Facebook. So, the question is:
Given an access token, can my (server-side) web application somehow get the post content, or at least the missing numbers? Preferably using the Facebook SDK, but any solution will do.
Update:
As #CBroe points out, simply querying the post id itself gives you enough info to recreate the post content:
.../v2.3/(post-id)?fields=name,message,picture,link
So, the last piece of the puzzle is to get the missing numbers. "Likes - On Post" can be found by querying the post's /likes with a summary:
.../v2.3/(page-id_post-id)/likes?limit=0&summary=true
..but "Comments - On Post" and "Shares - On Post" are trickier.
Querying .../v2.3/(page-id_post-id)/comments does give the number of comments on the post, but doesn't include answers to those comments, which are included in the number 5 in the picture above. You can recursively query /comments on each comment id, but that would generate too many queries to be worth it.
One might think that querying .../v2.3/(post-id)/sharedposts could give you the number of times a post has been shared, but it only gives you a few of the shared instances (due to other users' privacy settings?)
to clarify, you're trying to get the number of likes, comments, and shares.
Likes [post_id]/likes?summary=True&limit=0
NOTE: You can also call it when calling the post fields [post_id]?fields=id,likes.summary(true).limit(0)
Comments [post_id]/comments?summary=true&limit=0
NOTE: comments edge has a param filter https://developers.facebook.com/docs/graph-api/reference/v2.3/object/comments which may be why you see different numbers
NOTE: You can also call then when calling the post fields [post_id]?fields=id,comments.summary(true).limit(0)
Shares [post_id]?fields=shares
the sharedposts edge is empty b/c you don't have "read_stream" permission for the user's posts, https://developers.facebook.com/docs/graph-api/reference/v2.3/object/sharedposts#readperms
Edit (by OP):
Adjustments to get the same numbers that are presented in the "Post Details" popup:
Comments - On Post: (page-id_post-id)/comments?filter=stream&summary=true&limit=0
Using only post-id without prepending page-id gives the same result, but you also get a debug message saying "...actual number of results returned might be different depending on privacy settings."
Shares - On Post: (post-id)/sharedposts?fields=id
Don't prepend page-id here - that yields an empty result set.
Sadly, ?summary=true doesn't work, so I used the fields filter just to reduce the amount of data.
The suggested (post-id)?fields=shares gives a different number which seems similar to the insights numbers, but doesn't add up to any of them.

Facebook Graph API - Get list of id's and names that have liked a post

Using the Facebook Graph API, how do I get the list of people who have liked a specific item (say a post)? Doing a call like /ITEM_ID/?fields=likes using the Graph Explorer I'm able to see a list of names in the [data] array, but, when I call it from a website it doesn't display the names, it just shows the count value.
I'm thinking it's one of two things, but I'm not sure:
I'm using the wrong access token. I'm using the extended one for the fan page the post is on.
Facebook just doesn't give out that info to someone (or a fan page) that isn't the owner of the original post. (I'm the one who made the post.)
Is there a way to get the list of user names and user id's that have liked a post, and if so, what's required to do so?
There could be 2 reasons-
You access token is not correct. You need the read_stream permission for getting the posts.
You are not parsing the resulted JSON correctly.
/ITEM_ID?fields=likes.fields(id,name)
i have done this like this ( me/feed?fields=likes.fields(id,name) ) and it works

Get only timeline posts, from facebook feed request

I'm trying to build an app using facebook's JS SDK and Graph API, and got a little confused in process. The idea is simply to take every post user have created on his timeline. As listed in docs to do this you need to call feed connection, to get an array of post object representing posts users make to their wall.
The thing is when using standard request to get last 30 post (with read_stream permission)
FB.api('/me/feed?limit=30&format=json', function(response) {
//operations on response.data
}
in response graph api returns not only the timeline posts user made, but also some of comments on other peoples posts. So it seems feed doesn't return just "The user's wall." posts, as written in doc, but all things user posted. Request to */user_id/posts* is giving pretty much the same result.
The confusing part is that user text posts to his/hers timeline and comments on other people's posts have the same type of "status". The difference between them is that timeline post has it's content in "message" field and comment stores text in "story".
So my question: Is there a way to sort only timeline posts made by user, within a request itself?
So after facebook updated it's docs it is now clear that you need to call /{user-id}/posts to show only the posts that were published by user.
Call to /{user-id}/feed on the other hand returns the feed of posts, including status updates and links published by user, or by others on user's profile.
More about so called "derivative edges" here: https://developers.facebook.com/docs/graph-api/reference/user/#edges

Facebook graph API: feeds missing in json response

I try to fetch user's feeds via graph api from my Android application. It generally works but some feeds that I can see on the wall are missing in the json response.
I call the url http://graph.facebook.com/someUserId/feed, by using the Android Facebook SDK methods, so the access token should be provided automatically, but it's not really relevant I think in my case. Nevertheless fyi, the user of my app is authenticated via OAuth.
I already checked the following:
all the user's feeds are visible to everyone / public (set in privacy settings)
the json response is not cached by my browser
I am aware of paging, but this is not an issue. The problem is not that I am not getting the very oldest feeds but that some feeds are just missing in between.
I registered a new facebook user which is not connected to the user I want to retrieve the wall feeds from, and when I open the respective wall I see all the feeds there, as expected, since they're all public to everyone. Yet, when I open the same related json url unter http://graph.facebook.com/someUserId/feed, some feeds are missing.
This is an example of the problem - since all my posts are public, I can just call the json url directly in a browser to do a test.
I want to get wall feeds from user:
http://www.facebook.com/mathias.lin
Screenshot1: note the 3 marked postings, all posted by myself
and here the json response, as you can see, the 1st and 3rd wall posts are included in the json, but the 2nd post is not. Why?
The related json url is:
http://graph.facebook.com/mathias.lin/feed
I am getting the 'missing' feed when I add an access_token to the url - but why? The posted feed has a privacy setting for 'everyone'?!
This is the missing feed that I get when using the access_token:
{"id":"504063796_485195138796","from":{"name":"Mathias Lin","id":"504063796"},"message":"Photo test upload from Android","picture":"http:\/\/photos-e.ak.fbcdn.net\/hphotos-ak-snc6\/hs021.snc6\/165194_485195123796_504063796_6062399_1841907_s.jpg","link":"http:\/\/www.facebook.com\/photo.php?fbid=485195123796&set=a.485195118796.256450.504063796","name":"Torres Photos","icon":"http:\/\/static.ak.fbcdn.net\/rsrc.php\/yz\/r\/StEh3RhPvjk.gif","actions":[{"name":"Comment","link":"http:\/\/www.facebook.com\/504063796\/posts\/485195138796"},{"name":"Like","link":"http:\/\/www.facebook.com\/504063796\/posts\/485195138796"}],"privacy":{"description":"Everyone","value":"EVERYONE"},"type":"photo","created_time":"2011-01-06T05:10:43+0000","updated_time":"2011-01-06T09:00:23+0000","likes":6,"comments":{"data":[{"id":"504063796_485195138796_3607414","from":{"name":"Mathias Lin","id":"504063796"},"message":"Awesome, photo upload now works as well. Not so much fun working with the Facebook SDK for Android, would have expected more functionality beyond that just very very simple graph api wrapper. But need to be considered that the android sdk development was part of an internship - but since it's it's open source, it can luckily be modified. Which has to be done due to some bugs (mixing up the bundle parameters for a post, getString, getByteArray). Api documentation could be improved.","created_time":"2011-01-06T05:26:04+0000"},{"id":"504063796_485195138796_3608020","from":{"name":"Renate Hermanns","id":"628810487"},"message":"Wow
, how fast time passes by. Your daughter is nearly grown up ;-).","created_time":"2011-01-06T09:00:23+0000"}],"count":2},"attribution":"Torres"}
I've already posted the question to the FB dev forum, awaiting response.
Related threads:
http://forum.developers.facebook.net/viewtopic.php?id=81365
http://forum.developers.facebook.net/viewtopic.php?id=75984
Facebook Graph API "/userid/feed" returning Blank
Your approach is correct, I've seen the JSON and yes it's missing the second one, I think it's upload app form adroid, try checking the application settings for this app. Or If your trying to retrieve the wall FQL is a much better way
SELECT post_id, actor_id, target_id, message FROM stream WHERE source_id in (SELECT target_id FROM connection WHERE source_id=<uid> AND is_following=1) AND is_hidden = 0
I've been through this, the way Facebook is categorizing their permissions is somehow misleading, for example Publicly available may sounds like Available to everyone on Facebook but apperantly it's not.
Now in your case, if you already authenticated the user, then try using:
/me/feed
I guess this is the only case where access_token is not needed in the URL.
I had a similar problem. But for me, the problem was related to not setting the scope properly on first login (to authorize the app). I posted a similar question and got an answer that worked for me here:
Facebook API how to get all wall items