Tips & Tricks

Get Facebook Page Detail Using Graph API and PHP

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

[cc lang=”php”]

// 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);
[/cc]

Expert Developer on Facebook

Output

[cc lang=”php”]
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://localhost/xpertdev” (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
[/cc]

Also you can get individual values as per below method.

[cc lang=”php”]
var_dump($content->name);
// output
string “Expert Developer” (length=16)
[/cc]

Shares:
  • […] on Jan 2, 2012 in Code Snippet | 0 comments In previous post I have explined about getting the Facebook page details using Graph API and PHP. Now this post is about to get the Twitter Follower Count using PHP.For this method what you will […]

    Reply
  • […] aus der XPertDeveloper.com Blog gibt es ein Tutorial zeigt, wie Verwendung der Facebook Graph API zur Seite Details zu erhalten über eine einfache cURL Anfrage ( cURL PHP-Unterstützung erforderlich für das Beispiel). Hier […]

    Reply
  • Bruce C
    February 3, 2012 at 3:42 am

    Great info. Works well!

    Reply
  • Kevin
    Kevin
    March 8, 2012 at 2:00 am

    Awesome! works great…Thanks!

    Reply
  • Adam
    Adam
    May 6, 2012 at 8:19 pm

    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?!

    Reply
  • rambo
    rambo
    July 26, 2012 at 9:05 am

    Its not working.
    Message :
    boolean false

    Reply
  • arth
    arth
    October 1, 2012 at 2:40 pm

    its not working everytime it returns null….

    Reply
    • Avinash
      October 1, 2012 at 10:01 pm

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

      Reply
  • ZHicham
    ZHicham
    November 20, 2012 at 6:44 am

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

    Reply
    • Avinash
      November 21, 2012 at 10:32 pm

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

      Reply
  • rajeev
    rajeev
    January 20, 2018 at 12:45 pm

    i want to use it in android studio do you know how to implement it in android studio.

    Reply

Leave a Reply

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