How to Get Facebook Page Like Count In PHP Using FB Graph API

In this tutorial I’ll show you How to Get Facebook Page Like Count In PHP Using FB Graph API, This is latest and updated version and works well with new version of facebook graph api. In older version you can directly fetch fb likes by just passing the facebook page username/id but in updated version of Api, you must have to pass your facebook app id and secret key, So by using updated method I have created a simple php function, So that you can easily extract facebook page details in json format.

Here is the function in PHP

function fbPageLikeCounter($pageUid, $appid,$appsecret)
    $result = json_decode(file_get_contents(''.$pageUid.'?access_token='.$appid.'|'.$appsecret));
    if($result->likes) {
    	return $result->likes;
    } else {
    	return 0;

In the above function you just need to pass facebook page username/id, appid and secret key.
For generating facebook app id and secret you have to create facebook app on facebook developer panel. You can see this tutorial to creating facebook app.

Getting facebook page likes.

echo fbPageLikeCounter('[Fb_page_name/id]','[App_Id]','[App_Secret_Key]');

See live demo and download source code.



If you like this post please don’t forget to subscribe my public notebook for more useful stuff