We launched a new product at Harkable last week called Daily Pulse – which tracks social data for any URL, you can also subscribe to receive email reports. I thought i’d share a bit of functionality similar to how we engineer Daily Pulse.
Below is a super simple function that retrieves a JSON feed of comments, likes and shares for any URL you provide.
function facebook_shares($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_shares('https://www.facebook.com/redbull');
// facebook share count
echo $fb[0]->share_count;
// facebook like count
echo $fb[0]->like_count;
// facebook comment count
echo $fb[0]->comment_count;
yhgfhdfghfghfghgf
Excellet article. Loved the layout of the website too especially the fixed red top bar. Here I have combined a list of api and examples to fetch social count data from various services like facebook, twitter, gplus etc. Have a look here: http://cube3x.com/get-social-share-counts-a-complete-guide/
Nice find, thanks!
Noticed a bug: it’s good to free memory after calculations but
unset [$fb_json] in the function will never be called.
P.S. This is crazy – if I press “left” cursor button in the comment area, my Firefox (12) sets off to some other posts on this site.
Thanks for sharing this!
Is the function grabbing the comments themselves, (is that comments_fbid), or just does it grab just the counts?
If it’s just the counts, is it possible to grab the content of the comments in a similar way?
Designer and web developer, Co-founder and Technical Director at Harkable.com London. Previously I worked at InMobi, Spotify and MySpace. Interests include photography and making short videos. Also an avid F1 fan. I also run Mega Infographics for your daily dose of the best infographics.
Follow us on Twitter and get in-stream updates.
Subscribe to all the Papermashup tutorials and articles straight to your RSS reader.
Sign up and get all the Papermashup tutorials straight to your inbox.
6 discussions around Display Facebook likes / Shares PHP function