Blog

How to get Facebook likes count of a page using Graph API 2.8 Ver

This is an updated and working code snippet which can be used to retrieve Facebook like count of a specific page. To use this code snippet you’ll need a Facebook App ID and Secret Key. This use latest 2.8 API version method.

Step 1: 
Go to https://developers.facebook.com/ login with your facebook account. If you don’t have one you have to create one.
Step 2:
Created an app from facebook developer.
Step3:
You have to get App ID and App Secret from app you created.

Step 4:
PHP Code to get facebook like count of a page.

<?php

function fbLikeCount($id,$appid,$appsecret){

 $json_url =‘https://graph.facebook.com/’.$id.‘?access_token=’.$appid.‘|’.$appsecret.‘&fields=fan_count’;

 $json = file_get_contents($json_url);

 $json_output = json_decode($json);


 //Extract the likes count from the JSON object

if($json_output->fan_count){

 return $fan_count = $json_output->fan_count;

}else{

 return 0;

}

}

echo fbLikeCount(‘coregenie’,‘___APPID___’,‘___APPSECRET___’);

?>

Please edit your page name , app id, app secret.

This method is working. Tested on 1/5/2017

Leave a Reply


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