This topic contains 10 replies, has 2 voices, and was last updated by  Anna 1 month ago.

  • Author
    Posts
  • #1362 Reply

    Shubham Kumar
    Keymaster

    I had received some question from you guys that you are unable to count Facebook share using Facebook Graph API which I had shared in my article http://mycodingtricks.com/php/2-ways-to-count-facebook-likes-shares-and-comments-using-php/ . So I’m just giving you another solution of how you can count Facebook share, likes and comments using PHP and FQL query and it doesn’t need any access token.

    Here is the URL which you have to call to count the likes, share and comments of a status or URL:

    https://api.facebook.com/method/fql.query?format=json&query=SELECT+url,normalized_url,total_count,share_count,comment_count,like_count,click_count,commentsbox_count+FROM+link_stat+WHERE+url+%3D+%27mycodingtricks.com%27

    Replace mycodingtricks.com with your Actual URL and it will return a json code looks like:

    [{
    "url":"http:\/\/mycodingtricks.com",
    "normalized_url":"http:\/\/www.mycodingtricks.com\/",
    "total_count":1,
    "share_count":1,
    "comment_count":0,
    "like_count":0,
    "click_count":0,
    "commentsbox_count":0
    }]

    Now you can use PHP to count the shares, likes and comments:

    
    <?php
    function getData($url){
     $json = json_decode(file_get_contents("https://api.facebook.com/method/fql.query?format=json&query=SELECT+url,normalized_url,total_count,share_count,comment_count,like_count,click_count,commentsbox_count+FROM+link_stat+WHERE+url+%3D+%27".$url."%27"),true);
     return $json;
    }
    
    $count = getData("http://mycodingtricks.com");
    echo "Likes : ".$count['like_count'];
    echo "Shares : ".$count['share_count'];
    echo "Comments : ".$count['comment_count'];
    ?>
    

    You can also Use jQuery to count share, likes and comments.

  • #2135 Reply

    Murshid

    Dear shubham how to count a specific post of user in fb

  • #2246 Reply

    Dinesh

    Hi shubham.,

    How to get the particular facebook post like, share and comments count?

    • #2385 Reply

      Shubham Kumar
      Keymaster

      I will share a complete article on that topic very soon. Have patience.

  • #2372 Reply

    Taz

    If i integrate this in my app on android, how can i implement the auto fetching of $url for every post i share ? Example : i share a post from my own FB account linked to another app by ACTION_SEND, now i want that app to show these stats without manually entering the URLs.

    I hope i am clear, thanks,

  • #2834 Reply

    Marcial Soto

    In my case, the code retrieves as an array, so the print code will be:

    echo $count[0][‘share_count’];

  • #3472 Reply

    Pete

    FQL is nos longer supported

  • #3803 Reply

    Jose A Dominguez

    Hi Shubham,
    Is there a way to know if a user is a fan of my facebook page?
    My code is not working…….

    FB.api(‘/me/likes/page id’,function(response){
    if( response.data ){
    if( !isEmpty(response.data) ) alert(‘You are a fan!’);
    else alert(‘Not a fan!’); }
    else { alert(‘ERROR!’); }
    }); // function to check for an empty object function isEmpty(obj) { for(var prop in obj) { if(obj.hasOwnProperty(prop)) return false; } return true; }

  • #3883 Reply

    Anna

    Hallo Leute, ich habe den Code in meiner Seite drin. Seit einer Weile werden die SeitenLIKEs nicht mehr angezeigt 🙁
    Man soll nun einen neuen Code mit http://graph.facebook.com/?ids=YOURURL nehmen. Kann mir hier jemand helfen?

    <?php
    function facebook_count($url){

    // Query in FQL
    $fql  = “SELECT like_count”;
    $fql .= ” FROM link_stat WHERE url = ‘$url'”;

    $fqlURL = “https://api.facebook.com/method/fql.query?format=json&query=” . urlencode($fql);

    // Facebook Response is in JSON
    $response = file_get_contents($fqlURL);
    return json_decode($response);

    }

    $fb = facebook_count(‘https://www.facebook.com/MEINESEITE’);

    // facebook like count
    echo $fb[0]->like_count;
    Echo ‘test’;
    ?>

Reply To: Count Facebook Share, likes and comments with FQL Query
Your information: