Facebook Cookbook - Jay Goldman [121]
start_time
string
Start time in epoch seconds. See Formatting Relative Time for more about epoch seconds.
end_time
string
End time in epoch seconds. See Formatting Relative Time for more about epoch seconds.
creator
int
uid (user ID) of the user who created this event.
update_time
string
Last time this event was updated in epoch seconds. See Formatting Relative Time for more about epoch seconds.
location
string
Location of this event. This is a free text field, so this could be anything.
venue
array
An array containing the street address, city, state, country, latitude, and longitude of the venue.
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 events, see the Events.get() method in Chapter 9.
Event Member Table
Problem
What’s the schema of the event_member table?
Solution
The event_member table records the relationships between events and users, as well as their RSVP status. Its fields are listed in Table 8-6. Queries to this table will only return data the current user is allowed to see (meaning you can’t request events for users the current user isn’t friends with). More information about this table, including an up-to-date listing of fields, can be found at http://wiki.developers.facebook.com/index.php/Event_member_(FQL).
Table 8-6. event_member table fields
Name
Type
Index
Description
eid
int
•
eid (Event ID) of this event.
uid
int
•
uid (User ID) of the Facebook user whose RSVP status is recorded in this entry.
rsvp_status
string
The user’s RSVP status. Can be one of attending, declined, unsure, or not_replied.
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 event_members, try the Events.get() and Events.getMembers() methods.
Retrieving an Event
Problem
I need to retrieve a Facebook event using FQL.
Solution
If you have the eid (event ID) of the event, this is easy:
SELECT eid, name, pic_small, description, start_time,
end_time, location FROM event WHERE eid = $eid;
You can, of course, SELECT a different set of fields.
Discussion
The only place you can get an eid using FQL is from the event_member table (see Event Member Table). This query will only return events that the current loggedinuser has permission to see.
Retrieving Events Created by a User
Problem
I need to retrieve all of the Facebook events created by a specific user using FQL.
Solution
SELECT eid, name, pic_small, description, start_time,
end_time, location FROM event WHERE creator = $user AND eid IN (SELECT eid
FROM event_member WHERE uid = $user);
Discussion
This will return content only if the current loggedinuser can see the events of the user specified in $user.
Retrieving a User’s Events
Problem
I need to retrieve a specific user’s Facebook events using FQL.
Solution
Retrieving all of a specific user’s events is easy:
SELECT eid, rsvp_status FROM event_member WHERE uid = $uid
Discussion
Keep in mind that this will return events only if the current loggedinuser is allowed to see them. If you query for a user that the loggedinuser isn’t friends with, you’ll get an empty results set.
Retrieving a User’s Events with a Specific RSVP
Problem
I need to retrieve a specific user’s event based on their RSVP.
Solution
SELECT eid, rsvp_status FROM event_member WHERE rsvp_status = $status AND uid = $user;
Discussion
There are four possible statuses for event_member records: attending, declined, unsure, or not_replied. Keep in mind that this solution will return events only if the current loggedinuser is allowed to see them.
Retrieving Events Two Users Are Attending
Problem
I need to find all of the events that two users are attending, using FQL.