Jerry McPhoton
Jerry McPhoton

Reputation: 75

Returning a list of user friends in facebook graph api using php

I'm having trouble (yet again) with returning a list of friends for a specific user. This is the code:

   $friends = $facebook->api('/me/friends');
 echo $friends;  

However, it does not display anything on the page at all. Does anyone know how to fix this?

Upvotes: 2

Views: 1883

Answers (1)

Darvex
Darvex

Reputation: 3644

Yup, you have to provide active access token. If I remember correctly you need special permission to see user's friend list too.

$token = $facebook->getAccessToken();  $friends = $facebook->api('/me/friends', 
                          'GET', 
                           array (
                             'access_token' => $token));

Update: Friends lists are included with the basic permissions. The Facebook API reference says:

Read

You can read the list of a User's friends by issuing an HTTP GET to /PROFILE_ID/friends with any valid access_token of the current session user. For example:

https://graph.facebook.com/me/friends

Upvotes: 3

Related Questions