facebookpluginssocial-media

How I can get count of likes from page on my website?


How I can get count of likes from page on my website? In my case I have page with news list, for example. And I want to show under each news count of likes, is there an easy and simple way to do that?


Solution

  • here is a code you can use for that

    <?php require_once 'src/facebook.php';
    
        $facebook = new Facebook(array(
          'appId'  => 'xxxxxxxxx',
          'secret' => 'xxxxxxxxxxxx',
          'cookie' => true,
        ));
    
    
        $fanpage = $_GET["fanpage_id"]; 
        $width = $_GET["width"]; 
        $height = $_GET["height"];
        $fontfamily = $_GET["fontfamily"];
        $fontsize = $_GET["fontsize"]; 
        $fontcolor = $_GET["fontcolor"]; 
        $backgroundcolor = $_GET["backgroundcolor"]; 
        $backgroundimage = $_GET["backgroundimage"]; 
    
    
        $result = $facebook->api(array(
            'method' => 'fql.query',
            'query' => 'select fan_count from page where page_id = '.$fanpage.''
        ));
    
        $fb_fans = $result[0]['fan_count'];
    
        echo '<style>
        #likes{
            width:100px;
            height:100px;
            font-family:Verdana;
            font-size:14px;
            color:#000;
            }
        </style>
        ';
    
    
        echo '<div id="likes">';
        echo ''.$fb_fans.'';
        echo '</div>';