Last active
August 29, 2015 13:55
-
-
Save stormwarning/8713037 to your computer and use it in GitHub Desktop.
Return a count of Facebook Likes, Shares, Comments from Fan Pages.
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 | |
/** | |
* Return the number of Likes, Shares, or Comments of a given Fan Page. | |
*/ | |
function facebook_numbers( $url ) { | |
$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 = "' . $url . '"'; | |
$apifql = 'https://api.facebook.com/method/fql.query?format=json&query=' . urlencode( $fql ); | |
$fb_json = file_get_contents( $apifql ); | |
return json_decode( $fb_json ); | |
} | |
$fb = facebook_numbers( 'https://www.facebook.com/FANPAGE' ); | |
$fb_shares = $fb[0]->share_count; | |
$fb_likes = $fb[0]->like_count; | |
$fb_comments = $fb[0]->comment_count; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment