Get Group Members

Problem

I need to find all of the members of a group.

Solution

Use the Groups.getMembers() method:

$members = $facebook->api_client->groups_getMembers(12345);

where 12345 is the gid (group ID) of your target group.

Description

Groups.getMembers() returns a multidimensional array in which the first level of elements are the four membership types (members, admins, officers, not_replied), each containing the appropriate set of uids representing all of the members of that category whom the current loggedinuser is allowed to see. Note that the members array contains all of the admins and officers but does not overlap with the not_replied array. These lists are not filtered for users of your application, so note that they might contain users who don’t have it installed.

FQL equivalent

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

SELECT uid, gid, positions FROM group_member WHERE gid=$gid

See Listing Table for more information.

Get Facebook Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.