Sometimes, being a programmer we may come across a need of a snippet where we have to show the count of likes of a Facebook page. This small code snippet given below uses FaceBook’s graph api and returns the likes count of the page. There is no need to have the FaceBook access token to call the api and get the result.
Remember, this only gives the count and not the persons who liked the page.
//The following code returns the Number of likes for any facebook page.
//Page Id of TechRecite.com. Replace it with your page.
$page_id = "138564926335348";
$likes = 0; //Initialize the count
//Construct a Facebook URL
$json = file_get_contents($json_url);
$json_output = json_decode($json);
//Extract the likes count from the JSON object
$likes = $json_output->likes;
//Printing the count
echo 'TechRecite.com has '.$likes.' Facebook Fans';
That’s it. Next tutorial explains how to get Facebook profile picture with custom dimensions