Facebook Cookbook - Jay Goldman [128]
Other interests of the artist on this Page, if applicable.
members
string
Members of the cast of the TV show on this Page, if applicable.
built
string
Year the vehicle on this Page was built, if applicable.
features
string
Features of the vehicle on this Page, if applicable.
mpg
string
Fuel economy (in miles per gallon) of the vehicle featured on this Page, if applicable.
general_info
string
General information about the entity on this Page, if applicable.
Note that only the fields marked as “Index” in this table can be used in an FQL query’s WHERE clause, but any of the fields can appear in the SELECT.
Discussion
Much like the schema for the listing table (see Listing Table), the page table has been seriously denormalized for performance reasons. A normalized schema for this page would move all of the fields specific to one type of listing into a secondary table for that listing type.
If you’d rather use the API to access page, try the Pages.getInfo() method.
Page Fan Table
Problem
What’s the schema for the page_fan table?
Solution
The page_fan table records the relationships between pages and users. Its fields are listed in Table 8-15. Queries to this table will only return data the current user is allowed to see (i.e., you can’t request fans for pages that the current loggedinuser can’t see). More information about this table, including an up-to-date listing of fields, can be found at http://wiki.developers.facebook.com/index.php/Page_fan_(FQL).
Table 8-15. page_fan table fields
Name
Type
Index
Description
uid
int
•
User ID of this user.
page_id
int
Page ID of the Page the user is a fan of.
type
string
Type of this Page. There are a way too many different Page types to enumerate here. You can see them on the Create a Page page ( http://www.facebook.com/pages/create.php). They’re generally stored in the database in all caps, with underscores in place of spaces (e.g., CONSUMER_PRODUCTS).
Note that only the field marked as “Index” in this table can be used in an FQL query’s WHERE clause, but any of the fields can appear in the SELECT.
Discussion
There’s a really obvious index missing from this table, which makes working with it a whole lot harder: page_id (although the field exists, the lack of an index on it means you can’t include it in FQL queries as part of the WHERE clause). As it currently stands, you can find the Pages a user is a fan of but not the users who are fans of a Page. It would fit better with the general FQL model to enable that index but only return users that the current loggedinuser is friends with, so maybe that will come in time.
If you’d rather use the API to access page_fan, try the Pages.getInfo() and Pages.isFan() methods.
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.
Retrieving a User’s Pages
Problem
I need to retrieve all of the Pages a specified user is a fan of using FQL.
Solution
SELECT name, type, pic_square FROM page WHERE page_id IN
(SELECT page_id FROM page_fan WHERE uid = $user);
Discussion
You’ll get an empty set if the current loggedinuser doesn’t have permission to see the Pages of the user you’re querying