Get FaceBook Friend Count [closed]

To get your friends as a JSON object from Facebook, you can use their Graph API. Easiest way is to visit this page:
http://developers.facebook.com/docs/reference/api/user/

Scroll down until you find the Friends link in the “Connections” table. That link will give you a JSON object containing all your friends. Note that the URL on that page is unique to you and contains your access token. Don’t share the link.

You can use this sort of code in WP to get and use that information:

$body = wp_remote_retrieve_body(wp_remote_get('YOUR_FB_URL', array('sslverify'=>false)));
$dec = json_decode($body);
echo count($dec->data);

You’ll want to use transients or something similar to cache the data so that you don’t ask FB for it all the time.

Leave a Comment