Blog

How can we count the likes of a facebook page using PHP code

Posted by : Leo T Abraham on 2 September, 2013

We can easily count the likes of a facebook page. The only thing that we need to know is the page id of the facebook page. If you know the page id of the facebook page, then simply use the following code:

<?php
    function likes()
    {
        $pageID = 'XXXXXXXXX';
        $info = json_decode(file_get_contents('http://graph.facebook.com/' . $pageID));
        echo $info->likes;
    }
    likes();
?>

Instead of XXXXXXXXX enter the page id of the facebook page. Also please note that, your page must have atlease one like. Otherwise it will raise PHP error.