Skip to content

Instantly share code, notes, and snippets.

@castroalves
Created April 29, 2014 17:08
Show Gist options
  • Save castroalves/11406340 to your computer and use it in GitHub Desktop.
Save castroalves/11406340 to your computer and use it in GitHub Desktop.
Facebook Friend Ranking
<?php
require_once( 'lib/facebook-friend-rank/fb-sdk/facebook.php' );
$config = array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
);
$permissions = 'read_stream, user_photos, friends_photos, read_mailbox';
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
?>
<html>
<head></head>
<body>
<?php
if($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
require_once( 'lib/facebook-friend-rank/ay-fb-friend-rank.class.php' );
$friendRanking = new AyFbFriendRank( $facebook );
$friends = $friendRanking->getFriends();
echo json_encode( $friends );
//$user_profile = $facebook->api('/me','GET');
//echo "Name: " . $user_profile['name'];
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl( array( 'scope' => $permissions ) );
echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
// No user, print a link for the user to login
$login_url = $facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '">login.</a>';
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment