Get Facebook Page Detail Using Graph API and PHP

  • Avinash
  • 18
  • Jan 01, 2012
  • Tips & Tricks

Here is the technique to get the detail of the Facebook page with Graph API and PHP. This is the very easy method to get the Facebook page detail. So Let’s see how to get this done.

With this method you can get below details of any Facebook page.

01) id
02) name
03) picture
04) link
05) likes
06) category
07) website
08) username
09) products
10) description
11) can_post
12) talking_about_count

I will show the example with the Facebook page of the Expert Developer. You can follow us on Facebook at Expert Developer.

Working Code

// 178585515507054 = Facebook page ID $url="https://graph.facebook.com/178585515507054"; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2); $content = curl_exec($ch); $content = json_decode($content); var_dump($content);
  // 178585515507054 = Facebook page ID
  $url="https://graph.facebook.com/178585515507054";
 
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
  $content = curl_exec($ch);
  $content = json_decode($content);
  var_dump($content);

Expert Developer on Facebook

Output

object(stdClass)[1] public "id" => string "178585515507054" (length=15) public "name" => string "Expert Developer" (length=16) public "picture" => string "http://profile.ak.fbcdn.net/ hprofile-ak-snc4/277010_178585515507054_5770865_s.jpg" (length=81) public "link" => string "http://www.facebook.com/expertdeveloper" (length=39) public "likes" => int 136 public "category" => string "Personal blog" (length=13) public "website" => string "http://www.xpertdeveloper.com" (length=29) public "username" => string "expertdeveloper" (length=15) public "products" => string "Website." (length=8) public "description" => string "This group is mainly belongs to the any person who involved in internet market industry anyhow." (length=95) public "can_post" => boolean true public "talking_about_count" => int 8
object(stdClass)[1]
public "id" => string "178585515507054" (length=15)
public "name" => string "Expert Developer" (length=16)
public "picture" => string "http://profile.ak.fbcdn.net/
hprofile-ak-snc4/277010_178585515507054_5770865_s.jpg"
(length=81)
public "link" => string "http://www.facebook.com/expertdeveloper"
(length=39)
public "likes" => int 136
public "category" => string "Personal blog" (length=13)
public "website" => string "http://www.xpertdeveloper.com" (length=29)
public "username" => string "expertdeveloper" (length=15)
public "products" => string "Website." (length=8)
public "description" => string "This group is mainly belongs to the any
person who involved in internet market industry anyhow."
(length=95)
public "can_post" => boolean true
public "talking_about_count" => int 8

Also you can get individual values as per below method.

var_dump($content->name); // output string "Expert Developer" (length=16)
  var_dump($content->name);
  // output
  string "Expert Developer" (length=16)

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by:

  • Pingback: Get Twitter Follower Count with PHP | Expert PHP Developer

  • Pingback: XPertDeveloper.com: Get Facebook Seite Detail unter Verwendung Graph API und PHP | PHP Boutique

  • http://www.hotwebideas.net Bruce C

    Great info. Works well!

    • http://www.xpertdeveloper.com Avinash

      Thanks

  • Kevin

    Awesome! works great…Thanks!

  • Adam

    Damn, it’s not woking :( I wrote codes in php files again and again i’m getting error messages. Would somebody tell what is a solution?!

    • http://www.xpertdeveloper.com Avinash

      What error you are getting? Can you post here?

  • rambo

    Its not working.
    Message :
    boolean false

  • arth

    its not working everytime it returns null….

    • http://www.xpertdeveloper.com Avinash

      make sure you have provided the proper/correct facebook user ID and most important is facebook is blocked from firewall?

  • ZHicham

    But how we can use these variables to echo them ….

    • http://www.xpertdeveloper.com Avinash

      In the last code block you can see that I have printed the name using the var_dump function.