Display Facebook Likes & Shares PHP function

Posted 3 years ago     3892      php

This PHP function below gets a JSON feed of comments, likes and shares for any URL you want.

function facebook_shares($url){

    $fql  = "SELECT url, normalized_url, share_count, like_count, comment_count, ";
    $fql .= "total_count, commentsbox_count, comments_fbid, click_count FROM ";
    $fql .= "link_stat WHERE url = '".$url."'";

    return json_decode($fb_json);


You can use it in the following format:

$fb = facebook_shares('https://www.facebook.com/redbull');

// facebook share count
echo $fb[0]->share_count;

// facebook like count
echo $fb[0]->like_count;

// facebook comment count
echo $fb[0]->comment_count;

Credit to papermashup


There are no comments yet.

You need to be logged in to post comments.

Welcome to Snippet Repo!

Discover, share and save useful code snippets.

Join our community over over 2,000 members! Currently a 48% acceptance rate. Apply for membership →