/ Published in: PHP
Use the facebook api to grab how many \\\'likes\\\' a url has had.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // the url to check how many likes $url = 'http://www.likewizard.com/like-67'; // build the facebook query $fburl = "http://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url='$url'&format=atom"; // grab the atom dump via facebook api url call above // it returns something like this: /* <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true"> <link_stat> <like_count>9</like_count> </link_stat> </fql_query_response> */ // grab the like count out, i hate dom parsing, so just use regex: $like_count = $matches[1]; echo "The URL $url has $like_count likes on facebook"; // OPTION 2 >>> keeping it to a 1 liner: $data = json_decode(file_get_contents("http://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url='$url'&format=json")); echo "The URL $url has " . $data[0]->like_count . " likes on facebook"; ?>
URL: http://codecanyon.net/forums/thread/help-atom-feed-to-database/28994