Facebook Like and Share count can easily be obtained from the Facebook Graph API. This is an extremely quick way to look up the JSON response from Facebook so that you can further process it for your own requirements.
<?php
$URL ='https://graph.facebook.com/cocacola';
$JSON = file_get_contents($URL);
$Output = json_decode($JSON);
$Likes = 0;
if($Output->likes){
$Likes = $Output->likes;
}
echo "Number of likes for CocaCola's Facebook Page = ".$Likes."</br>";
$URL2 ='https://graph.facebook.com/http://www.coca-cola.com';
$JSON2 = file_get_contents($URL2);
$Output2 = json_decode($JSON2);
$Shares = 0;
if($Output2->shares){
$Shares = $Output2->shares;
}
echo "Number of shares for coca-cola.com = ".$Shares;
?>
UPDATE 29/01/2012: I’ve written a slightly different method using the PHP SDK in this post here
Great method to do this – displayed in a very simple way.
Thanks a lot, you’ve really cut straight to the point of what I was needing!
Something I’ve noticed is that in your code example your quotes and inverted commas are formatted funny, when I copied and pasted I had to change them to the other kind.
Very nice code, really helped me.
Thank you.
Hey! I’m a kiwi too! Made an app that does this automatically and with the new API. Give it a try and let me know if you like it 🙂 https://www.facebook.com/games/analytics-scholatec/
Hi Loic,
Good work there, that makes it very simple for Facebook page owners to get some useful information.
I’m not really doing much FB development these days but good to see what you’re up to.