Last updated on July 7, 2017
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 result.you 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('https://graph.facebook.com/'.$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.