Sunday, November 23, 2014

How to Collect FaceBook Likes Count Using Graph API in PHP

Now-a-days, Social media plays a very important in the promotion of any website. Facebook is one of the top social media sites. It will look good if we can show Facebook page likes in our website. Facebook's graph API is the easiest way to collect the like count of a Facebook page. As a PHP Programmer, We need to write below code to grab the like count of particular Facebook page and display it on your website.

Collect FaceBook Likes Count in PHP

Get Facebook likes count in PHP

We need to pass user name and id of the particular page :-

//Get Facebook Likes Count of a page

function fbLikeCount($id){
//Construct a Facebook URL
$json_url ='https://graph.facebook.com/'.$id.'';
$json = file_get_contents($json_url);
$json_output = json_decode($json);
//Extract the likes count from the JSON object
if($json_output->likes){
return $likes = $json_output->likes;
}else{
return 0;
}
}
//This Will return like count of webprogramminghub's Facebook page
echo fbLikeCount('webprogramminghub');

0 comments:

Post a Comment