I need to fetch facebook likes,share, comments count from an article
Is there any way to fetch facebook (likes,share, comments) count.
Thanks in advance.
Actually you can have a more detailed report using FQL. Try following query:
Here the php code:
$fql = "SELECT url, normalized_url, share_count, like_count, comment_count, ";
$fql .= "total_count, commentsbox_count, comments_fbid, click_count FROM ";
$fql .= "link_stat WHERE url = 'www.apple.com'";
$apifql="https://api.facebook.com/method/fql.query?format=json&query=".urlencode($fql);
$json=file_get_contents($apifql);
print_r( json_decode($json));
And this is the expected result:
Array
(
[0] => stdClass Object
(
[url] => www.apple.com
[normalized_url] => http://www.apple.com/
[share_count] => 355693
[like_count] => 500374
[comment_count] => 290890
[total_count] => 1146957
[commentsbox_count] => 2
[comments_fbid] => 388265801869
[click_count] => 16558
)
)
This solution worked for me:
<?php
$source_url = "http://www.flightpodcast.com/episode-6-john-bartels-qantas-qf30";
$url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=".urlencode($source_url);
$xml = file_get_contents($url);
$xml = simplexml_load_string($xml);
echo "Share --- ".$shares = $xml->link_stat->share_count;
echo "<br/>";
echo "Like --- ".$likes = $xml->link_stat->like_count;
echo "<br/>";
echo "Comments ---".$comments = $xml->link_stat->comment_count;
echo "<br/>";
echo "Total --- ".$total = $xml->link_stat->total_count;
echo "<br/>";
echo $max = max($shares,$likes,$comments);
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