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 a Page

Problem

I need to retrieve a specific Page using FQL.

Solution

If you know the page_id of the Page you want, this is easy:

SELECT name, type, pic_square FROM page WHERE page_id = $page_id;

If you don’t know the page_id but do know the name, you can still find it, as long as you know a user who’s a fan:

SELECT page_id, pic_square, type FROM page WHERE name = $name
 AND page_id IN (SELECT page_id FROM page_fan WHERE uid = $user;

Discussion

This is a little harder than some of the comparable queries on other tables because there’s no way to do this without a subquery, which is dependent on having a uid. As noted earlier, the outcome is that this will work only when the current loggedinuser or one of his friends is a fan of the Page you’re looking for.

You’ll get an empty set if the current loggedinuser doesn’t have permission to see the Pages of the user you’re querying on.

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