Another, simpler way to display facebook fan count as text
March 25th, 2012 - 5 Comments »
I can now show you a much simpler way to display your Facebook fan count as text on your website. It is alot simpler than the previous way, although it is entirely up to you how you wish to display it.
Step 1 – Find out your Facebook pages ID
Page ID is the ID of your Facebook Fan Page. If you don’t have a Facebook Fan page, you’ll have to first create one. To get the ID of your Fan page, click edit page, and look for your ID (numbers) at the end of the URL – eg: http://www.facebook.com/pages/edit/?id=XXXXXXXXX
Step 2 – Copy and Paste
Copy and paste the code below anywhere within your website where you would like the Fan count to show. Remember to change the “XXXXXXXXXXXX” to your Facebook Pages ID.
|
1 2 3 4 5 6 |
<?php $page_id = "XXXXXXXXXXXX"; $xml = @simplexml_load_file("http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=".$page_id."") or die ("a lot"); $fans = $xml->page->fan_count; echo $fans; ?> |
There you have it, a much simpler way of displaying your fan count!
Related posts:









Hey,
Just want to say thanks for this. I have searching for this one tried many other links but not getting, Finally i got this link and thats it.
Not a problem Savan!
Thank you very much for the code, its working correctly! Can you please give me Google+ page circle count?
I think this is best and easy code article ever seen. i was searching for this right code…
thanks you very much
Just to say, I admire programmers with a sense of humour.
or die(“a lot”);
Nice work. This is also a very good tutorial, I used it on my clients’ websites too. Thanks.