Obtain Facebook likes via PHP SDK

In an update to this post here is another way to obtain the number of likes for a Facebook page.

I’ll assume that you’ve already registered a Facebook application, have downloaded the PHP SDK and have included for use in your code.

require('facebook.php');

Setup an array with your Facebook applications credentials

$facebook = new Facebook(array(
'appId' => '000000000', // Put appID here
'secret' => '0000c000c000c000c', // Put your secret key here
));

Decide which page you wish to obtain the number of likes for

$getRequest = $facebook->api('/cocacola'); // Lets look at the Facebook page for the popular soft drink
echo $getRequests['likes'];

Obviously you can consume, contrast and display this information in more exciting ways than simply echoing it to the screen. Enjoy.

4 thoughts on “Obtain Facebook likes via PHP SDK”

  1. Definitely – if you’re not loading the full SDK and want a quick like count using the Graph API is a great way to go. Thanks for the link.

Leave a Reply

Your email address will not be published. Required fields are marked *