Created
December 12, 2011 03:52
-
-
Save nobuhiko/1464710 to your computer and use it in GitHub Desktop.
facebook_likes ranking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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