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

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.

Related

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.

Where is "on shares" data found in Facebook's api?

Clicking a post in Facebook's post insights shows a summary like this:
I am however bamboozled as to how a post can have 8 likes, 3 comments and 2 shares on shares of this post, without that post having been shared ('0 on post').
Trying to gain further insight into this:
/{post-id}/insights doesn't return any share information.
/{post-id}/sharedposts returns an empty set, even for posts that have been directly shared.
/{page-id}/posts just indicates the "shares on posts" (not on shares) and even omits that if it's zero like in this case.
Where can I find the "On Shares" figures in the api?
Maybe "on shares" is from people who liked the post because their friend liked it. and the original person hasn't liked the page. because the same issue happened with my account 2 Point Perspective and it didn't receive any "shares"!!
As far as I can conclude, "on shares" numbers can be calculated by total minus "on post" numbers. You can get total numbers from
/{page_id}_{post_id}/insights/post_stories_by_action_type
and "on post" numbers from
/{page_id}_{post_id}/?fields=likes.limit(0).summary(true),comments.limit(0).summary(true),shares
You should be able to get these numbers from /{page_id}_{post_id}/sharedposts/..., but as of this bug report, you won't be able to do so actually.
Also watch out for permissions and Graph API version number.
Had to think this through for awhile, but I finally got it (I think).
What it's basically saying is the following.
First line: you received a total of 8 Likes. The 8 Likes didn't come from your direct post. It came from the shares of other users (however many shares that was).
Second line: same situation as above. Except this time, you had 1 comment on your direct post, while 3 comments came from shares.
Third line: you get the gist.
Here is the exact language that describes how this works from Facebook.
"The metrics you see on a Page post when viewed from your Page's Timeline or in News Feed include likes, comments and shares that happened on the original post. The metrics in your Page Insights include likes, comments and shares from the original post plus any activity that happened if your post was shared. For example, if someone shares your post, and then their friend shares that post, this will be counted as 2 shares in Page Insights."
Source: https://www.facebook.com/help/336143376466063/

How to check if a Facebook page post shared by a certain user?

I need a way to learn if a user had shared a post (link, video, photo etc.) which is published by a Facebook page. I have the object_id and link of the post, and user_id of the user considered. Is there a Graph API or FQL (or something else) solution to ask Facebook if the user re-shared the post or not? Or is it possible to get a list people who shared the post? So, I can extract my answer from this list.
Note that I know it is possible to find the answer by crawling the user's wall feed. But it is time consuming and I need a more efficient way.
Thanks in advance.
You can use the following FQL to get the data you're looking for.
SELECT via_id, created_time, owner_comment
FROM link
WHERE owner = me()
You can then compare via_id against the posts author (page ID) to determine if this share came from the page in question.
Unfortunately, there seems to be a bug with the data return where some of the via_ids come back as 0. There is a ticket in with Facebook which, at the time of this post, has been open for three weeks at medium priority. I have no idea if this issue is specific to my app or affects everyone, but that's the query to get what you want.

Facebook - check who shares a link

When I type name of e.g. youtube clip in facebook search I can get number of people that share this link.
Is it posibble to fetch list of people sharing given like using facebook api?
No, you can't get who shared, only the total number. The easiest way to see the count is, for instance:
http://graph.facebook.com/http://stackoverflow.com
This solved my problem !
http://graph.facebook.com/http://stackoverflow.com
Creating Facebook apps was very easy, but now, you need to apply and ask for approval the app ... that sucks ...
You can do this with Facebook's FQL (Facebook Query Language), it gives you more information than the previously mentioned Graph API method, but Facebook are apparently going to turn off the FQL API on August 7, 2016. So its not going to be useful in the long term.
https://api.facebook.com/method/fql.query?query=select+comment_count%2C+like_count%2C+total_count%2C+share_count%2C+click_count+from+link_stat+where+url%3D%27stackoverflow.com%27
The interesting thing about this is it shows the result given by the previously mentioned Facebook Graph API request, i.e:
http://graph.facebook.com/http://stackoverflow.com
is actually giving the "total count", which is actually the sum of the likes, comments and shares of that link, the FQL method gives you the actual individual counts for comments, shares and likes.
Another method for getting the actual share count, is to use the links.getStats API call, but it appears to be undocumented, and nobody seems to know how long it will be available for.
Here's how to use it:
https://api.facebook.com/method/links.getStats?urls=stackoverflow.com&format=json