Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home Facebook Graph API PHP Get Likes Number Of Facebook Page

PHP Get Likes Number Of Facebook Page

There are several ways to get the number of users who like a particular Facebook page, we can use both Facebook API or FQL to get that number. However, I’ll supply a simplest way to do that, just a few lines of code, we don’t need to register for a new Facebook app or request allow permission or anything.

In order to get the total number of likes, you just specify the Facebook Page Id or Name and use file_get_contents() PHP function to load return JSON encoded string from Facebook. In addition, the response string should be converted to an array by using json_decode() function for easier accessing.

PHP Get Likes Number Of Facebook Page

Assume that we need to get the likes number from 2 Facebook page, one with Facebook Name (4.Rapid.Development) and one with Facebook ID (19292868552).

+ Facebook Page – 4.Rapid.Development:

<?php
	$result = file_get_contents("https://graph.facebook.com/4.Rapid.Development");
	$result = json_decode($result,true);
 
	echo "name: " . $result["name"] . "<br>";
	echo "website: " . $result["website"] . "<br>";
	echo "likes: " . $result["likes"] . "<br>";
 
	echo "&lt;pre&gt;";
	var_dump($result);
	echo "&lt;/pre&gt;";
?>

Output:

name: 4 Rapid Development
website: http://4rapiddev.com
likes: 180
array(11) {
  ["id"]=>
  string(15) "192737727433644"
  ["name"]=>
  string(19) "4 Rapid Development"
  ["picture"]=>
  string(80) "http://profile.ak.fbcdn.net/hprofile-ak-snc4/187791_192737727433644_418020_s.jpg"
  ["link"]=>
  string(43) "http://www.facebook.com/4.Rapid.Development"
  ["likes"]=>
  int(180)
  ["category"]=>
  string(20) "Computers/technology"
  ["website"]=>
  string(20) "http://4rapiddev.com"
  ["username"]=>
  string(19) "4.Rapid.Development"
  ["founded"]=>
  string(10) "Hoan Huynh"
  ["location"]=>
  array(2) {
    ["city"]=>
    string(16) "Ho Chi Minh City"
    ["country"]=>
    string(7) "Vietnam"
  }
  ["can_post"]=>
  bool(true)
}

+ Facebook Page ID 19292868552:

<?php
	$result = file_get_contents("https://graph.facebook.com/19292868552");
	$result = json_decode($result,true);
 
	echo "name: " . $result["name"] . "<br>";
	echo "website: " . $result["website"] . "<br>";
	echo "likes: " . $result["likes"] . "<br>";
 
	echo "&lt;pre&gt;";
	var_dump($result);
	echo "&lt;/pre&gt;";
?>

+ Output:

name: Facebook Platform
website: http://developers.facebook.com
likes: 3401015
array(11) {
  ["id"]=>
  string(11) "19292868552"
  ["name"]=>
  string(17) "Facebook Platform"
  ["picture"]=>
  string(80) "http://profile.ak.fbcdn.net/hprofile-ak-ash2/276791_19292868552_1958181823_s.jpg"
  ["link"]=>
  string(32) "http://www.facebook.com/platform"
  ["likes"]=>
  int(3401015)
  ["category"]=>
  string(15) "Product/service"
  ["website"]=>
  string(30) "http://developers.facebook.com"
  ["username"]=>
  string(8) "platform"
  ["founded"]=>
  string(4) "2007"
  ["company_overview"]=>
  string(78) "Facebook Platform enables anyone to build social apps on Facebook and the web."
  ["mission"]=>
  string(37) "To make the web more open and social."
}

As you can see in the 2 simple example above, beside the “likes” number, we can get some other information such as: name, website, link, picture, category, etc of a Facebook page easily as long as we have its Facebook ID or Name.

Nov 16, 2011 Hoan Huynh
PHP Change Facebook Profile Picture With Graph APIPHP Load Facebook Albums And Save To MySQL Database
You Might Also Like:
  • Get Or Find Facebook Fan Page Id Number
  • PHP Get Facebook URL Total Comments, Total Likes, Total Shares
  • How To Ask People To Like Your Facebook Page On The Landing Page
  • Get or Find Facebook Profile Id Number
  • Get Facebook Total Comments, Total Likes, Total Shares Of A Given URL
  • Show Latest People Of Facebook Fan Page
  • Facebook Like Button And Recommend Button With fb:like, iframe and html5
  • String To Upper Case In PHP, JavaScript And .Net (CSharp)
  • String To Lower Case In PHP, JavaScript And .Net (CSharp)
  • ASP.NET Get Facebook URL Total Comments, Total Likes, Total Shares
  • J

    Thank you. It’s really better and faster than using FQL or Facebook API.

  • http://www.yphpmysql.com/ PHP Development

    Hi there, just wanted to impart that I think this blog is brilliant, it has just the information I am looking for. Please feel happy about the fact that this is only the 6th blog I have bookmarked in over 6 weeks. Keep up the good work and I look forward to making some more important comments over the weeks.

  • josh

    Nothing related but I like to share something I’ve found VERY useful. I highly recommend everyone to use Get Likes Facebook http://getlikesfacebook.com/. It’s free and I get ton of likes everyday. TRUST ME! Try it and thank me later!

    • thankyou

      sound great! however, are they real people or robot???

  • Puppen

    My favorite site to get free Likes is GetLikesEasy. It’s a fast and easy Like Exchange system and I’ve already gotten more than a thousand Likes. Check it out! http://GetLikesEasy.com

Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at hoan@4rapiddev.com

8 years ago Facebook Graph APIFacebook, file_get_contents, JSON, json_decode, var_dump241
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
18,765 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
14,632 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
13,366 views
JQuery Allow only numeric characters or only alphabet characters in textbox
10,933 views
C# Read Json From URL And Parse/Deserialize Json
7,502 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Magento Fatal error: Unsupported operand types
  • Ionic bower the name contains uppercase letters
  • PHP Magento Get Manufacturer Name And ID From Magento Product ID
  • Know Simple Hacks To Systematize Media Library in WordPress
  • A handy guideline on adding custom menu item in WordPress admin
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (26)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (140)
EMAIL SUBSCRIPTION

Sign up for our newsletter to receive the latest news and event postings.

Recommended
  • CDN
  • Hosting
  • Premium Themes
  • VPS
2014 © 4 Rapid Development