I'm trying to get the count for Facebook
shares with this function :
<?php
function get_likes($url) {
$json_string = file_get_contents('http://graph.facebook.com/?ids=' . $url);
$json = json_decode($json_string, true);
return intval( $json[$url]['shares'] );
}
echo get_likes("http://facebook.com");
?>
Sometimes, it's working (I get the good count), but sometimes I get zero share.
I didn't manage to identify the reason why (and I tried with tens URL from various websites). Moreover, when I go to this URL http://graph.facebook.com/?ids=http://facebook.com
, It always show the right information...
How is it possible to avoid this "zero share
" result ?