How to get shares count for a Photo in Facebook? - facebook

I want to get comments count, likes count and shares count for a page posts. I have their IDs and I'm trying to figure something out with the Graph API or FQL, but in vain.
For regular posts I can query the stream FQL table and I get the comment_info, like_info structures and shares_count variable.
For posted photos I can query the photo table and I get from there comment_info and like_info, but it lacks the shares_count.
I tried using Graph api like that: GET /550045508388715 and it returns a ton of information, but nothing related to share count.
I've googled that issue, but did not found any relevant solution.

Instead of GET /ID use GET /POST_ID to get the shares count (if >1). You'll get the result as-
"shares": {
"count": x
}
Note- the Post ID is generally: USERID_PHOTOID ORPAGEID_PHOTOID

Related

Can we get the share count of a post in fb using graph api v2.3?

I need to get the shares count of a particular post in fb uisng graph api.
I could'nt find any method to do so. I have followed the link below.
https://developers.facebook.com/docs/graph-api/reference/v2.3/object/sharedposts
It returns the data of the shared posts in pagination format.
Is there any way to get the total count of the shares without fetching the whole data and without paginating within the data?
Please suggest!!
Just the field shares should give you the number of shares for a POST_ID
[POST_ID]?fields=shares
Sample data from my feed
{
"shares": {
"count": 1
},
"id": "POST_ID",
"created_time": "2015-04-29T09:07:12+0000"
}
Get shares count :
114916098537132_1265715836790480?fields=shares
Bonus [ Get likes + shares + comments ]
114916098537132_1265715836790480?fields=shares,likes.summary(true),comments.summary(true)
Improved version ( add limit(0) to removes list of likes and get only summary ):
114916098537132_1265715836790480?fields=shares,likes.limit(0).summary(true),comments.limit(0).summary(true)

How to retrieve FB comments/shares for a specific URL

I would like to retrieve the text,author of comments or shares made for a specific url.
I have for instance the following target : http://www.graphemeride.com/blog/comment-j-ai-triche-aux-golden-blog-awards
I can retrieve the number of comments and shares with FQL :
SELECT
url, share_count , comment_count, comments_fbid
FROM
link_stat
WHERE
url="http://www.graphemeride.com/blog/comment-j-ai-triche-aux-golden-blog-awards"
I get the following result :
{
"data": [
{
"url": "http://www.graphemeride.com/blog/comment-j-ai-triche-aux-golden-blog-awards",
"share_count": 27,
"comment_count": 26,
"comments_fbid": 357167807708699
}
]
}
My plan was to use the comment FQL query to retrieve the different comments.
SELECT
id, text
FROM
comment
WHERE
object_id="357167807708699"
However I get an empty result dataset.
I added the required access token, but kind of understood that I can only get comments I made about this object, not public comments or shares.
Is there an alternative way to get access to what people publicly said about an url ?
The comment count on the link_stat table is the for the number of comments on the SHARES of this link and not the number of comments on the comments plugin on that page itself.
Whereas the comments table returns you the number of comments from the comments plugins on that page.
As your page isn't using any fb comments plugin, you don't get any comments back.

Search Facebook Graph API for long posts?

Is it possible to search the Graph API for posts a Facebook member has written where post.length > n ?
Or would I have to pull posts and parse/filter them in my code?
You can use FQL to make filtered Graph API calls.
This query will get you posts with a message containing the word "this" which are more than 50 characters long.
SELECT message, post_id FROM stream WHERE CONTAINS("this") and strlen(message) > 50 LIMIT 100
The CONTAINS() function is not documented. From my experimentation with it, it searches multiple fields and is optimized to return matches that are based on full names.

Getting from Facebook API total number of likes per post

I'm working with the following Facebook API endpoints: /statuses, /links, /photos
For each returned object I'm only getting likes and comments objects which display top25 results, and a pagination that leads to the next 25.
I'm only interested in the number of likes. Is there a way to get that number through a different API call which doesn't require multiple pagination calls?
You can return the total number of likes for various objects using FQL. Here's the documentation for how to get the total number of likes for a comment:
https://developers.facebook.com/docs/reference/fql/comment
The query itself would look like this:
SELECT likes FROM comment WHERE post_id = xyx
SELECT like_info.like_count FROM stream WHERE source_id = '<id>'
or
SELECT like_info.like_count FROM stream WHERE source_id = '<id>' and and actor_id = '<id>'
More: https://developers.facebook.com/docs/reference/fql/stream/

Query every liked object using FQL

I'm trying to query every object which the user has liked since joining facebook by running this query:
SELECT user_id, object_id, post_id FROM like WHERE user_id=me()
This query runs fine and returns some results, but the number of them is a lot less than I estimated. I tried it on different, real user accounts, and for a friend of mine who has joined facebook around 2006 the number of returned results is still only around 65.
I tried this query through the official javascript sdk and through the graph api explorer which gave identical results.
The documentation doesn't state any limit imposed upon querying the like table.
Is there anything, I should be aware when doing a query on this table?
Thank you very much!
According to this documentation :
Each query of the stream table is limited to the previous 30 days or
50 posts, whichever is greater, however you can use time-specific
fields such as created_time along with FQL operators (such as < or >)
to retrieve a much greater range of posts.
Although not explicitly mentioned in the doucmentation for likes, I guess this will be the same limit. So try to add created_time in a where clause.