Facebook Cookbook - Jay Goldman [124]
What’s the schema for the group table?
Solution
The group table stores the groups that have been created in the Facebook Groups app. Its fields are listed in Table 8-11. Queries to this table will only return data the current user is allowed to see (meaning you can’t request groups that the current loggedinuser can’t see). More information about this table, including an up-to-date listing of fields, can be found at http://wiki.developers.facebook.com/index.php/Group_(FQL).
Table 8-11. group table fields
Name
Type
Index
Description
gid
int
•
Group ID of this group.
name
string
Name of this group.
nid
int
Network ID that this group belongs to, if any.
pic_small
string
URL of the small picture for this group (max width of 50 px and max height of 150 px). Might be empty if this field wasn’t set by the creator.
pic_big
string
URL of the big picture for this group (max width of 200 px and max height of 600 px). Might be empty if this field wasn’t set by the creator.
pic
string
URL of the picture for this group (max width of 100 px and max height of 300 px). Might be empty if this field wasn’t set by the creator.
description
string
Description of this group.
group_type
string
Type of group. Can be any one of Business, Common Interest, Entertainment & Arts, Geography, Internet & Technology, Just for Fun, Music, Organizations, Sports & Recreation, or Student Groups.
group_subtype
string
Subtype of this group. Subtypes are tied to the type, and each has between 3 and 20 options.
recent_news
string
Contents of the Recent News as set by a group admin.
creator
int
User ID of the creator of the group.
update_time
string
Last time this event was updated in epoch seconds. See Formatting Relative Time for more about epoch seconds.
office
string
Contents of the office field as entered by the creator of the group.
website
string
Contents of the website field as entered by the creator of the group.
venue
array
An array containing the street address, city, state, and country of the venue of the group.
Note that only the field marked as “Index” in this table can be used in an FQL query’s WHERE clause, but any of the fields can appear in the SELECT.
Discussion
If you’d rather use the API to access groups, try the Groups.get() method.
Group Member Table
Problem
What’s the schema for the group_member table?
Solution
The group_member table records the relationships between groups and users. Its fields are listed in Table 8-12. Queries to this table will only return data the current user is allowed to see (i.e., you can’t request groups that the current loggedinuser can’t see). More information about this table, including an up-to-date listing of fields, can be found at http://wiki.developers.facebook.com/index.php/Group_member_(FQL).
Table 8-12. group_member table fields
Name
Type
Index
Description
uid
int
•
User ID of this user.
gid
int
•
Group ID that this user belongs to.
positions
array
Any positions in the group that this user may occupy. If the user has no position in this group, positions will be null; otherwise, it will be an array listing each of her positions. Looks like the possible positions are ADMIN and OFFICER, but that’s not documented anywhere.
Note that only the fields marked as “Index” in this table can be used in an FQL query’s WHERE clause, but any of the fields can appear in the SELECT.
Discussion
If you’d rather use the API to access groups, try the Groups.get() and Groups.getMembers() methods.
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