2

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.

Euclécio
  • 174
  • 5
  • 15

2 Answers2

2

You can´t get all friends anymore, you can only get friends who authorized your App with the user_friends permission too. The answer in this thread (and countless others) will tell you more: Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130
0

The solution was put user_friends on permissions in Facebook Login

$permissions = ['email', 'user_friends'];
$loginFbUrl  = $helper->getLoginUrl($serverUrl, $permissions);
Euclécio
  • 174
  • 5
  • 15
  • you know, that is in my answer already...(user_friends permission), and there is NO way to get ALL friends. – andyrandy Nov 09 '17 at 07:49