May 28, 2014 11:24 am

How to get Facebook page fan count using FQL in PHP

We all have Facebook pages for brands, Public Profile etc, and most of us add our Facebook page widget in website’s sidebar which is traditional like box and simple count of likes. In this tutorial I will give you a very small code of PHP using that code you can get any Facebook page likes in text format with name and you can show your fan count in a nice layout to your users according to your theme.

How to get Facebook page likes using FQL in PHP

Also Read: How to post into a Facebook Page with PHP using Graph API

This is a very simple and easy to configure script I am using FQL query with Facebook API.

     $data = file_get_contents(',name+from+page+where+page_id%3D254602424641921');

     $decode = json_decode($json);
     echo $decode[0]->fan_count;
     echo $decode[0]->name;

Above code send request to Facebook API for fan_count and name page counts and name of the page in FQL with format json means returning data will be in json format after that we decode json and echo fan_count and name of page.

This is a very simple and short and very useful code. I hope it helps you please give us your feedback.

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.

Tutorial Categories:

One response to “How to get Facebook page fan count using FQL in PHP”

  1. rahul says:

    there is a error it called undefined variabe jason on line ($decode = json_decode($json);)

Leave a Reply

Your email address will not be published. Required fields are marked *