Get Facebook Likes Count with PHP

Facebook Likes Count with PHP

This tutorial will help you to get Facebook Likes, Shares and Comments of any Facebook Page or External Link. I have make a function fb_count() that will fetch Facebook likes, shares and comments from Facebook Database. Under this function we make a query that will get likes, shares and comments from facebook database and response us in form of JSON (JavaScript Object Notation). We use Facebook API, that will pass our query to facebook and then give us response. This script can be useful if you are developing social widget that will show your social links, you can show your likes though this script.

DEMODOWNLOAD

First we make a function that will pass one parameter and that parameter is our link.

Then under this function first we make a query and ask it to SELECT share_count, like_count and comment_count from a table named link_stat. Obviously we need a KEY for for it so our Link or URL will be the KEY for this query.

Then we use Facebook API to pass above Query. After passing this query we will get our response in JSON.

When facebook response us in JSON we need to decode that JSON it can be through Buil-in function json_decode().

Now it’s time to pass our Link or URL to get likes, shares and comments. Simply I use finction fb_count() and provide it a parameter as a Link or URL.

Wait a minute! There is nothing shown in page :'(

Keep Calm and Read

As I told you we get response in JSON so obviously we have to echo that response.

For facebook Shares Count

For Facebook Likes Count

For Facebook Comments Count

That’s all!

DEMODOWNLOAD

6 Comments

  1. Fer (@finlayzon) June 15, 2015
  2. Hafiz Abdullah Majid June 15, 2015
  3. Ad * September 9, 2015
  4. Abdullah Majid October 20, 2015
  5. Sam August 21, 2016
  6. Sam August 21, 2016

Leave a Reply