Get Groups
Problem
I need to retrieve information about a set of groups, based on either a list of users or group IDs.
Solution
Use the Groups.get()
method:
$groups = $facebook->api_client->groups_get();
If you specify no filters, you’ll get all the groups for the
current loggedinuser. You can
specify a different user’s uid to
filter for them:
$groups = $facebook->api_client->groups_get(12345);
In that case, you’ll get something back only if the current
loggedinuser is allowed to see the
groups for the user you’ve specified. If you have one or more gids (group IDs) and just want to pull
information on them, you can do that too:
$targetGroups = array('2248774311', '14740918186');
$groups = $facebook->api_client->groups_get(null, $targetGroups);Discussion
Groups.get() returns a multidimensional array of group records, with
each element containing the fields listed in Groups Table.
FQL equivalent
If you’d prefer to use FQL to access groups, the equivalent query is:
SELECT gid, name, description FROM group WHERE gid IN (SELECT gid FROM group_member WHERE uid=$uid) AND gid IN ($gids)
See Groups Table for more information.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access