Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [143]

By Root 737 0
and make sure to report any bugs you might find into the Facebook Bug Tracker at http://bugs.developers.facebook.com.

FQL equivalent


If you’d prefer to use FQL to access cookies, the equivalent query is:

SELECT uid, name, value, expires, path FROM cookies WHERE uid=12345 AND name='Foo'

For more information, see Cookie Table.

Getting Events


Problem


I need to retrieve an event.

Solution


Use the Events.get() method, which allows you to filter for one user, a series of events, start/end times, and/or RSVP status. To filter for one user, specify null for the other filter parameters:

$events = $facebook->api_client->events_get(12345, null, null, null, null);

To retrieve one or more events, pass an array of event IDs (eids) as the second parameter:

$events = $facebook->api_client->events_get(null,

array(14381739642,16044821668), null, null, null);

If you specify both a uid and an array of eids, Platform will return the events in the array that the user has on his list:

$events = $facebook->api_client->events_get(12345, array(14381739642,

16044821668), null, null, null);

You can add in a start and/or end time (in epoch seconds; see Formatting Relative Time for more info) to further filter the results:

$events = $facebook->api_client->events_get(12345, array(14381739642,

16044821668), 1209600000, 1214827199, null);

The final argument is to filter by a specific RSVP status, which are attending, unsure, declined, and not_replied:

$events = $facebook->api_client->events_get(12345, null, 1209600000,

1214827199, 'declined');

Discussion


Events.get() will always return only those events that the current loggedinuser is allowed to see, regardless of who you specify as the uid filter (you’ll get an empty set of events back if the user isn’t allowed to see any of the events that should have been in the set).

The Client Library will return a multidimensional array in which each element contains all of the fields shown in Table 8-6.

FQL Equivalent


If you’d prefer to use FQL to access events, the equivalent query is:

SELECT eid, name, tagline FROM event WHERE eid IN (SELECT eid FROM

event_member WHERE uid=uid)

See Event Table for more information.

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 '

    ';

    for($counter = 0; $counter < count($members['attending']); $counter++){

    $uid = $members['attending'][$counter];

    echo '

  • ';

    echo ' '

    echo ' ';

    echo '

  • ';

    }

    echo '

';

}

}

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.

Refreshing FBML Caches


Problem


I need to tell Facebook to refresh its caches for some of my stored data.

Solution


If you’re caching images, use the FBML.refreshImgSrc() method:

$return = $facebook->api_client->fbml_refreshImgSrc

('http://www.someserver.com/images/some_image.jpg');

If you’re caching URLs, use the FBML.refreshRefUrl() method:

$return = $facebook->api_client->fbml_refreshRefUrl

('http://www.someserver.com/page.php');

Discussion


This returns true (1) if Facebook is able to locate an entry in its cache with the url you passed in and can refresh, or false

Return Main Page Previous Page Next Page

®Online Book Reader