Skip to content

Instantly share code, notes, and snippets.

@nobuhiko
Created December 12, 2011 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobuhiko/1464710 to your computer and use it in GitHub Desktop.
Save nobuhiko/1464710 to your computer and use it in GitHub Desktop.
facebook_likes ranking
<?php
// googleのsitemap xmlを使ってurlを抽出する
$google_xml_url = 'http://nob-log.info/sitemap.xml';
$limit = 10;
// urlのリストを作成する
$xml = simplexml_load_file($google_xml_url);
foreach($xml->url as $data){
$urls[] = $data->loc;
}
// fqlを作成する
$fql = " SELECT
url, like_count
FROM
link_stat
WHERE
url IN ('". implode("','", $urls). "')";
$fql_query_url = "https://api.facebook.com/method/fql.query?format=json&query=".urlencode($fql);
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
foreach ($fql_query_obj as $key => $row) {
$like_count[$key] = $row['like_count'];
}
array_multisort($like_count, SORT_DESC, $fql_query_obj);
echo '<pre>';
print_r(array_slice($fql_query_obj, 0, $limit));
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment