Posted By

ginoplusio on 10/08/12


Tagged

php count to read in how facebook likes


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

nicklarosa


How to read facebook like count for a url with PHP


 / Published in: PHP
 

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

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.

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

Report this snippet  

You need to login to post a comment.