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

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).

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