How to get Facebook page fan count using PHP ?

It’s pretty easy to obtain the like count via Facebook’s Graph Api.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 will receive result as a JSON object and you can extract the number of likes from it.

Simple Function to Get Facebook Page fan Count

function getPageFanCount($page) {
	$pageData = @file_get_contents(''.$page);
	if($pageData) { // if valid json object
		$pageData = json_decode($pageData); // decode json object
		if(isset($pageData->likes)) { // get likes from the json object
		   return $pageData->likes;
	} else {
		echo 'page is not a valid FB Page';

How to use Above function

In order use getPageFanCount() function you have to pass page id as parameter as shown below

  echo getPageFanCount($page = 'Arjunnetin');

That’s it.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems. Protection Status