Home » Home Server » Get Facebook like count using PHP

Get Facebook like count using PHP

The Facebook fanbox is pretty neat. It displays the Facebook like count as well as the pictures of the fans. One drawback to it is that it occupies a lot of space on your blog. In this post, I am going to explain how to get Facebook like count for your fan page with a simple PHP script. Check my other post for getting Twitter followers count using PHP. Another major drawback is that a fancy Facebook fanbox, which displays stream, faces, etc. will delay the page loading significantly. For this reason you may find that many of the blogs just provide a link to their Facebook fan page. I personally like to provide a like button on the blog, which makes it convenient for the visitors to like the page with just a couple of clicks.

Get Facebook like count
Facebook Fanbox

PHP code to get Facebook Like Count

The PHP script to get Facebook like count is pretty simple and straightforward:

$fpageID = '133529600097002';
$finfo = json_decode(file_get_contents('http://graph.facebook.com/' . $fpageID));
$fbcount = $finfo->likes;

$fpageID is the variable to hold your fanpage ID. You can get it from your Facebook fanpage:

Facebook Fanpage ID
Facebook Fanpage ID

After you get Facebook like count, you can display it as simple text using the following PHP code:

echo $fbcount.' like htpcbeginner.com';

This will output 25 like htpcbeginner.com.

You can even get counts of your Twitter followers and Feedburner subscribers and add them all together and display a combined followers count like this:

Combined Followers Subscribers Count
Combined Followers Subscribers Count

Facebook Like Count History

Although you may be able to get the Facebook like count history and more by other means, I like to record the data in a format I like. I currently get Facebook like count, Twitter followers count, FeedBurner subscribers count, and Alexa site rank and record them in a MySQL database daily to see the growth of my blog. If you make any changes / improvements to your blog then you have the data to see what impact it had on your followers count. In a separate post, I will explain how to accomplish this.

Meanwhile, get Facebook like count using the above script, get creative, and find innovative ways to use the count. Please do not forget to share your idea with us in the comments sections.

We Are Hiring: Familiar with Media Streaming, HTPC, Home Server, Smart Home, and Home Automation topics? Write about it and earn money. No writing experience needed. APPLY HERE.

Get 20% OFF with IPVanish VPN:

♦   Hide your browsing and streaming activity: No logs and no tracking
♦   Access geo-restricted content from anywhere
♦   Encrypt and anonymize: Kodi, Plex, Downloads, Personal Info
♦   Windows, Mac, Linux, Android, iOS, Router, and more.
♦   Money back guarantee - Sign Up Now

About the author

Anand

Anand is a self-learned computer enthusiast, a part-time blogger, and a Food Scientist by career. He has been blogging since 2010 on Linux, Ubuntu, Home/Media/File Servers, Smart Home Automation, and related HOW-TOs on htpcbeginner.com and smarthomebeginner.com.