Facebook php-sdk v4 get friend list
10,101
You will get only those friends who are using same Facebook application.
\Facebook\FacebookSession::setDefaultApplication('id','secret');
$session = new \Facebook\FacebookSession('access_token');
// Check user's token is valid or not.
$me = (new \Facebook\FacebookRequest(
$session, 'GET', '/me/friends'
))->execute()->getGraphObject(\Facebook\GraphUser::className());
$result = $me->asArray();
// Get user's friends
$friends = $result['data'];
// Converting classes to array
foreach ($friends as $key => $value) {
$friends[$key] = (array)$value;
}
Author by
user3581183
Updated on June 04, 2022Comments
-
user3581183 almost 2 years
i'm using new facebook php sdk v4 and I want to retrieve full list of friends Code:
try { $user_friends = (new FacebookRequest( $session, 'GET', '/me/friends' ))->execute()->getGraphObject(GraphUser::className()); echo '<pre>'; print_r($user_friends); } catch(FacebookRequestException $e) { echo "Exception occured, code: " . $e->getCode(); echo " with message: " . $e->getMessage(); }
But the result is:
Facebook\GraphUser Object ( [backingData:protected] => Array ( ) )
Login url parameters:
$loginUrl = $helper->getLoginUrl(array( 'publish_actions', 'user_friends', 'public_profile' ) );
Is this feature is disabled? There is another way to get a list of friends?
Thank you in advance