By using Graph API I can retrieve comments, likes count of both internal and external Facebook url. But I can only get the shares count of external Facebook url
For example:
https://graph.facebook.com/?ids=http://www.youtube.com/watch?v=tu8BNocnVzc
But not a facebook one:
http://graph.facebook.com/?ids=http://www.facebook.com/photo.php?fbid=364861533533284
How can I get the share numbers of a Facebook object?
(I can get likes and comments by using this url http://graph.facebook.com/364861533533284)
The previous answer is correct in one thing - you should use FQL. It's slower but it works. As for the rest - it won't work at all because the API won't return share_count for the photo link because it is an internal for Facebook and has PHP parameters in the link itself or some other unknown reason.
It's not good that the API won't return such information since it's public in most cases so they should implement that but however that doesn't work.
The thing that kind of works though is to retrieve the Post Link connected with that photo and count its shares.
Heres the code used:`
$photo_link = $photo['link'];
//First Query - Find the ID of the Post for the Photo
$query_post_id = "SELECT post_id, permalink FROM stream WHERE source_id = '[PAGE_OR_USER_ID]' AND permalink = '$photo_link'";
$fb_post_info = $facebook->api(array('method' => 'fql.query', 'query' => $query_post_id));
$id = $fb_post_info['0']['post_id'];
$whole_id = $fb_post_info['0']['post_id'];
$fb_post_id = explode('_', $id);
$fb_post_id = $fb_post_id['1'];
//Second Query - Find the Share Count Using the Post Link (not the Photo link)
$query_share_count = "SELECT share_count FROM link_stat WHERE url='http://www.facebook.com/[PAGE_OR_PERSONAL_USERNAME]/posts/$fb_post_id'";
$post_info = $facebook->api(array('method' => 'fql.query', 'query' => $query_share_count));
$share_count = $post_info['0']['share_count'];
echo $share_count;
?></span>`
The first query returns an array of the post ID and permalink. The post ID looks like this: PAGEID_POSTID, for example 3333333333_453536456464, so we have to split it to get just the second part which is the post ID found in the permalink.
After that we construct our link for the post which usually looks like this: facebook.com/USERNAME/posts/POSTID and then retrieve the share count for that link. Here you can also use the Graph API to get the share_count.
That's the only way to get the information that I've found till now - it's kind of sloppy because FQL is slower and some times the updates for the shares don't show up for a certain amount of time but as I said - it kind of works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With