Getting Event Members
Problem
I need to retrieve the users who are attending an event.
Solution
Use the Events.getMembers()
method:
$members = $facebook->api_client->events_getMembers($eid);
where eid
is the ID of the
event whose members you want to retrieve.
Discussion
This will return a multidimensional array in which the first
level contains the different RSVP statuses and the second level is the
uid
(user ID) of the member who
RSVPed. The four possible statuses are attending
, unsure
, declined
, and not_replied
. If you wanted, for example, to
list all of the people who are attending the event with eid
12345, you could do the
following:
$members = $facebook->api_client->events_getMembers('12345'); if($members){ if($members['attending']){ echo '<ul>'; for($counter = 0; $counter < count($members['attending']); $counter++){ $uid = $members['attending'][$counter]; echo '<li>'; echo ' <fb:profile-pic uid="' . $uid . '"/>' echo ' <fb:name uid="' . $uid . '"/>'; echo '</li>'; } echo '</ul>'; } }
FQL equivalent
If you’d prefer to use FQL to access your event members, the equivalent query is:
SELECT uid, eid, rsvp_status FROM event_member WHERE eid=eid
See Event Member 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.