Retrieving Five Albums for a User
Problem
I need to retrieve some (or all) of the albums for a specific user from the Facebook Photos app using FQL.
Solution
The simplest form of this query is:
SELECT aid, cover_pid, name, link FROM album WHERE owner = $uid LIMIT 5;
Discussion
When you’re imposing a limit on the data that gets returned, you
might want to add an ORDER BY
clause so that you’re getting some logical subset. With the case of
something like albums, it might
make sense to get the five albums most recently updated by a
user:
SELECT aid, cover_pid, name, link, modified FROM album WHERE owner = $uid ORDER BY modified DESC LIMIT 5;
The DESC
added to the
ORDER BY
when using a timestamp as
the ordering field will give you results in reverse chronological
order (i.e., newest first).
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.