Return to Snippet

Revision: 59897
at October 8, 2012 22:23 by ginoplusio


Initial Code
function readFacebookLikes($url) {
    $query = "select total_count from link_stat WHERE url ='" . $url ."'";
    $s = file_get_contents("https://api.facebook.com/method/fql.query?query=".
             urlencode($query)."&format=json");
    preg_match("#(\"total_count\"):([0-9]*)#",$s,$ar);
    if(isset($ar[2])) return $ar[2]; else return null;
}

Initial URL
http://www.barattalo.it/2012/10/08/how-to-read-facebook-likes-count/

Initial Description
When you add facebook like button to your site, probably, you also want to save the number of likes of your pages to your database.These data are very useful and very important because they tell you which of your articles are better than others. Moreover, these pages are better than others because the user has decided to tell his friends about it.

Initial Title
How to read facebook like count for a url with PHP

Initial Tags
php, facebook

Initial Language
PHP