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

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

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

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

Enjoy – or fork!