Facebook Insights - Post Details - facebook

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.

Related

FB graph API get post comments by given user

Do you know if its possible to get the list of post comments by given user?
I tried this: <post_id>/comments?fields=from.id(<user_id>) but it still returns array of all post comments. I think I have enabled all the permissions because I can see the from field but it looks like 1) the filter is not working, 2) I am doing it wrong. The graph API version I am using is v9.0
My goal is to get list of comments by given user or receive an empty array if the user didnt comment the post. Maybe there is a different way how to do it..
You cannot do this by calling the graph api anymore :/
But, there is some kind of workaround you may be able to do.
First, you'll have to set a page webhook to retrieve all the comments written on your page. Find the documentation here: https://developers.facebook.com/docs/pages/realtime
The information sent to your server via the new comment's webhook contains the "from" data, looking like this:
{
name: "Foo Bar", // the user's name
id: "12345" // A user ID (unique for your page. Will be different for the same user accross 2 different pages)
}
You may then be able to pick only the wanted user's comment
I clearly see 3 downsides to this workaround:
It only works with pages
You need to handle in realtime all the comments written on your page
You cannot retrieve the comments posted in the past

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

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.

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

FB graph API problems with reading posts (type=status)

I'm trying to analize a large number of posts from varoius pages for my bachelor thesis. Therefore I'm using a tool called Facepager which uses the graph API to fetch data from Facebook.
I need the following data:
id, link, type, from and the count of likes, shares and comments (just the numbers, no further info!). In general, everything is working just fine, only posts classified type=status behave strangely. For some of these posts, there is no data shown about like, share and comment counts, further more there is no link given. But as mentioned before, this only happens sometimes! I searched for the affected posts manually on facebook and some of them had a large number of likes, shares or comments.
I also tried to fetch data with graph API explorer with similar results.
Is there any reason why it isn't possible to get share, like and comment count on some of the posts classified type=status?
Additionally, I'm planning to use the ID or if invalid, the link to open specific posts in my browser. This is not possible for some of the status posts either.
Sorry for that newbie question, it would be amazing if I could get an answer because at the moment I am quite desperate because this is really important for my bachelor thesis. Thanks a lot!
Because this kind of post is a post which "CAN NOT BE VIEWED".
ex: "xxxx likes a link", or "XXX commented on a post".
I suggest that you should filter out these posts by yourself.

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