O'Reilly logo

Facebook Cookbook by Jay Goldman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Get Friends

Problem

I need to retrieve all of the current loggedinuser’s friends.

Solution

Use the Friends.get() method:

$friends = $facebook->api_client->friends_get();

You can optionally specify a flid (friend list ID) if you want to narrow the scope of the retrieval down to a single friend list:

$friends = $facebook->api_client->friends_get(12345);

You can find the flids for this user by calling Friends.getLists() (see Get Friend Lists).

Discussion

Friends.get() returns an array of uids for the matching friends.

This method will only return friends of the current loggedinuser. There is no way to call this for a different user. It is against the terms of use of Facebook Platform to store the returned values from this call.

FQL equivalent

If you’d prefer to use FQL to access friends, the equivalent query is:

SELECT uid2 FROM friend WHERE uid1=$uid

See Retrieving a User’s Friends for more information.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required