Get Facebook like count using PHP

PHP Facebook Likes Count
  • Share:
  • share htpcBeginnerShare on FacebookhtpcBeginner on Google+Tweet It

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('' . $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';

This will output 25 like

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.

Like this post? Share it and get Raspberry Pi OpenELEC Media Center 45-page eBook for Free!

Incoming Search Terms:

facebook like count in php, facebook like php, facebook like with count script


Leave a Reply

Review our comments policy.

Get your free comments avatar.


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>