Show Number of Facebook Likes in PHP

If you run a Facebook page, and you are starting to build up some good numbers, you may want to show them off on your website. Facebook allows you to embed a Facebook widget on your homepage, but that means you are using third-party scripts, and you can’t control the design. Here is a simple PHP snippet for displaying your Facebook Likes on your website.


$facebook_page_id = "127012630783508";
$results = @simplexml_load_file("http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=${facebook_page_id}");
echo $results->page->fan_count;

Leave a Reply

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