Search code examples
phpfacebooksdkfacebook-friends

Getting friends with facebook API PHP SDK v5.1


I need get all friends of logged user (only id, name, and picture).

/* Facebook API */
$fb = new \Facebook\Facebook([
    'app_id'                => FB_APP_ID,
    'app_secret'            => FB_APP_SECRET,
    'default_graph_version' => FB_DEFAULT_VERSION
    ]);
$accessToken = $_SESSION['fb_access_token'];

$response = $fb->get('/me/friends', $accessToken);
$graphEdge = $response->getGraphEdge()->asArray();
print_r($graphEdge);die;

But returns always empty.


Solution

  • The solution was put user_friends on permissions in Facebook Login

    $permissions = ['email', 'user_friends'];
    $loginFbUrl  = $helper->getLoginUrl($serverUrl, $permissions);