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

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

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.

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.

How to get all user's likes using facebook's graph API

How can I query facebook's graph API to retrieve all user's likes (not only pages but also photos and others)?
For instance, how could I get all the pictures a user has liked? Using facebook's search bar you can find them easily by clicking on "photos has liked".
I wrote a script that scrapes the page content and does that but it's not very efficient.
I have recently come accross a similar problem, maybe this helps you solve it.
https://graph.facebook.com/v2.5/{page_id}/feed?fields=likes.limit(1).summary(true)&since={start_date}&until={end_date}&access_token={access_token}
This will give you a list of all posts that received likes during the specified time period. If you manage to write a code summing up the following JSON path you got your sum for "all user's likes":
data[0].likes.summary.total_count
Not entirely sure is this is exactly what you were searching for, hope it helps you though - and if not you, someone else.
As for likes you can also use the same way to extract Shares and Comments:
Shares
https://graph.facebook.com/v2.5/{page_id}/feed?fields=shares&since={start_date}&until={end_date}&access_token=
Comments
https://graph.facebook.com/v2.5/{page_id}/feed?fields=comments.limit(1).summary(true)&since={start_date}&until={end_date}&access_token=
Best regards
There isn't to my knowledge any way to get this from the API without grabbing every type of response from the API and then sorting through for likes. Facebook search bar uses an internal API different from the Graph API.

facebook graph api does not return all feed items on facebook page

at the time of this question, if you go here:
http://www.facebook.com/realplayer
you'll see six posts down, I have posted a photo with a message of "#highfive Cincinnati, OH"
but if you to either of these:
http://graph.facebook.com/realplayer/feed
http://graph.facebook.com/realplayer/tagged
the JSON that is returned seemingly includes everything on the wall, except for MY post. there is another photo post from someone else down below mine, and it is showing up (and both my photo and his photo are in the "Fan photos" section)
obviously, since I can see everything with these links already, it appears that access_token is not a part of the equation... BUT, some more info:
if I use an access_token from a session that isn't me, I can't see the post in the JSON
if I use an access_token from MY logged in session, then I DO see the post in the JSON
so I'm very confused.
if everyone in the world can see those posts on the wall without even authenticating, then I expect all of them to come back in the graph api as well.
anyone have thoughts on this?
I am aware of the "manage_page" permission... which I can use to get a list of accounts and special offline access tokens for those pages... and that's something I can explore... but it seems like alot of work when my post seemingly SHOULD be there in the graph
well looks like FB has this nice little anti-spam feature for pages... such that a non-admin can't write lots of messages on your page. what's interesting is that facebook uses similar "silent treatment" techniques that StackOverflow uses ( https://blog.stackoverflow.com/2008/09/podcast-21/ )... so when I look at a wall that I've been "spamming" I will see all of my posts... but no one else will.
I was able to create a new test account and get about 3 or 4 messages on a page before it started blocking me again
so probably the Graph API is working as designed :)
========================
UPDATE: this appears to only be part of the problem. I have constructed another page and app and been doing testing:
http://www.facebook.com/pages/RP-Test-Page/116735865065591
note the entry for "#highfive Orlando, FL" ... even an unauthenticated user can see this entry from the actual page... but there is seemingly no way for me to get it back through the API. He only posted once, so it can't be an "anti-spam" thing (you wouldn't think).
I have obviously tried the Graph API (with and without my own access token)
I have tried FQL (with and without my own access token)
and I have followed this post:
http://en-gb.facebook.com/topic.php?uid=10381469571&topic=3815&post=51980
in order to request manage_pages and offline_access extended permissions from myself and use that to get the /me/accounts and then get the "impersonation" access token (whew)... STILL NOTHING
there must be some other super security thing going on. is it not possible to reliably get all of the wall posts from a page?