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

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.

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