Euclécio
Euclécio

Reputation: 174

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.

Upvotes: 2

Views: 2910

Answers (2)

Euclécio
Euclécio

Reputation: 174

The solution was put user_friends on permissions in Facebook Login

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

Upvotes: 0

andyrandy
andyrandy

Reputation: 74014

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

Upvotes: 2

Related Questions