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

Retrieving a Specific Group

Problem

I need to retrieve a specific group using FQL.

Solution

If you know the gid of the group, it’s as easy as:

SELECT name, description FROM group WHERE gid = $gid;

It’s a little trickier if you know the name of the group but not the gid. As long as the user is a member of the group, you can do this:

SELECT gid, nid, description FROM group WHERE name = $name
 AND gid IN (SELECT gid FROM group_member WHERE uid = $user);

Discussion

The current loggedinuser needs to be allowed to see the specified group or you’ll get back an empty set. Two things to note if you’re looking up a group by name:

  • Groups aren’t unique by name, so you may well get more than one result back.

  • Remember that it’s an exact match, so you’ll need to get punctuation and capitalization exactly right.

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