Getting stats from the Facebook Like button your way

So you’ve implemented the Facebook Like button, and you’d like to know – programmatically – what your users Like on your site. This is a bit of a pain, since there’s nothing in the Facebook Open Graph for this. There’s some stuff in the insights api, but it’s not really usable if you’d like to do anything fun with your data.

I’ve written a PHP class which you can download and use anyway you see fit. It’s kind of simple, but will get the job done. You probably want to add some caching to it, since the old REST-api we’re querying isn’t very responsive.

Use it like this:

# create new instance of like class
$FbLikes = new FbLikes();

# add all the urls you want to measure
$FbLikes->addUrl('http://earthpeople.se/labs/');
$FbLikes->addUrl('http://wplove.se/kom-pa-wpbar/');
$FbLikes->addUrl('http://debaser.se/');

# set the sort order, either 'likes' or 'untouched'
$FbLikes->order_by = 'likes';

# get all the fb like data
$likes = $FbLikes->getLikes();

# echo the results
if($likes){
  foreach($likes as $row){
    echo $row->normalized_url . ': ' . $row->like_count . " facebook likesn";
  }
}

Enjoy – or fork!

One thought on “Getting stats from the Facebook Like button your way

  1. This is very useful for th gamification aspect of application. Thank you for the Development of this php class. I want to track the pages my players are interacting with. This was exactly what I was looking for.

Comments are closed.