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]
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]
[…] 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 […]
[…] 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 […]
Great info. Works well!
Thanks
Awesome! works great…Thanks!
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?!
What error you are getting? Can you post here?
I want show counts on sidebar.php, so which codes (‘working code’ and ‘output’) i should write to where, to sidebar.php or functions.php ? If i write ‘working code’ to sidebarp.php it says ‘there is no fctn. like curl_init(). And if i write that to functions.php, there is again a problem :( Write details please :)
If you are getting error message like curl_init() is not defined, the i am sure that you do not have CURL installed.
Have to enable (install) curl ?
Are you running on windows or Linux?
Windows, using WAMP
I have not tried these links but you can try and post your response over here:
http://www.phpmind.com/blog/2011/02/how-to-enable-curl-in-wamp/
http://techsporting.blogspot.in/2009/03/install-curl-for-wamp-in-windows.html
http://in.answers.yahoo.com/question/index?qid=20090827212635AAWBwZj
Best Luck ;)
Its not working.
Message :
boolean false
its not working everytime it returns null….
make sure you have provided the proper/correct facebook user ID and most important is facebook is blocked from firewall?
But how we can use these variables to echo them ….
In the last code block you can see that I have printed the name using the var_dump function.
i want to use it in android studio do you know how to implement it in android studio.