There are many api that gets the Facebook points like Shares, Likes, Comments and returns it. This Tutorial will get the Facebook likes, shares and comment counts of a specific URL using a php function. The function uses the FQL api of the Facebook and get the data using JSON. The PHP Function returns the Facebook Likes, Shares and Comment Counts. Here is the sample of FQL query to be used on facebook.
FQL Query:
$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."'";
JSON CODE:
$apifql="https://api.facebook.com/method/fql.query?format=json&query=".urlencode($fql);
By using this, you can easily manage and design your Facebook points/stats depending on what you want or your theme designed and not limited on what the Facebook buttons has.
Now lets put it together and make it work. We will combine this in a function.
PHP CODE:
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."'";
$apifql="https://api.facebook.com/method/fql.query?format=json&query=".urlencode($fql);
$fb_json=file_get_contents($apifql);
return json_decode($fb_json);
}
HOW TO DISPLAY IT
$fb = facebook_shares('https://www.facebook.com/');
echo 'The URL https://www.facebook.com/ has ';
// facebook share count
echo ' fb shares:'.$fb[0]->share_count;
// facebook like count
echo ' fb likes:'.$fb[0]->like_count;
// facebook comment count
echo ' fb comments:'.$fb[0]->comment_count;
Thats it, we’ve get the facebook stat count of a certain URL. Hope that it helps you on your project.
Let others try and know this by sharing this tutorials. Thanks
DEMO DOWNLOAD [tweegi-button name="tweetandgetit"]
Incoming search terms:
- $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 = www apple com; $apifql=https://api facebook com/method/fql query?format=json&que
- facebook post comment count javascript
- how to get comment count of latest tweet in php
- how to get facebook page comment count query in php
- how to get likes for public search query in facebook using php
wilbert Santos
He is the founder and the man behind Upgraded Tutorials that focuses on creative and helpful web development tutorials. He is a Web Developer and knows CodeIgniter, WordPress and other frameworks. He loves web development and creating cool stuff. Add him on Facebook and Google
- Web |
- Google+ |
- More Posts (11)






