Created
August 14, 2013 10:08
-
-
Save itsjavi/6229683 to your computer and use it in GitHub Desktop.
PHP function for getting batch url stat counters (likes, shares, ...)
This file contains hidden or 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 | |
| function facebook_url_stats($urls, $orderBy = "ORDER BY like_count DESC") { | |
| $urls = implode("', '", $urls); | |
| $urls = "'" . $urls . "'"; | |
| $fql = "SELECT url, normalized_url, share_count, like_count, comment_count, "; | |
| $fql .= "total_count, commentsbox_count, comments_fbid, click_count FROM "; | |
| $fql .= "link_stat WHERE url IN ({$urls}) {$orderBy}"; | |
| $apifql = "https://api.facebook.com/method/fql.query?format=json&query=" . urlencode($fql); | |
| $json = file_get_contents($apifql); | |
| $result = json_decode($json); | |
| $result_assoc = array(); | |
| if (is_array($result)) { | |
| foreach ($result as $i => $r) { | |
| $result_assoc[$r->url] = $r; | |
| } | |
| } | |
| return $result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment