Facebook Cookbook - Jay Goldman [123]
Checking for a Friend Request Between Two Users
Problem
I need to check to see whether there’s a pending friend request between two specific users using FQL.
Solution
SELECT uid_to, uid_from FROM friend_request WHERE uid_from
= $user2 AND uid_to = $user1;
Discussion
You can run this query only when user1 is the current loggedinuser.
Friend List Table
Problem
What’s the schema for the friendlist table?
Solution
The friendlist table stores the friend lists created by users to organize their friends. Its fields are listed in Table 8-9. Queries to this table will only return data the current user is allowed to see (i.e., you can’t request friendlists for users other than the current loggedinuser). More information about this table, including an up-to-date listing of fields, can be found at http://wiki.developers.facebook.com/index.php/Friendlist_(FQL).
Table 8-9. friendlist table fields
Name
Type
Index
Description
flid
int
flid (friendlist ID) of this friend list.
name
string
Name of this friend list.
owner
int
•
uid (user ID) of the owner of this friend list. You can query only on the current loggedinuser.
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
If you’d rather use the API to access friendlists, try the Friends.getLists() method.
Friend List Members Table
Problem
What’s the schema for the friendlist_member table?
Solution
The friendlist_member table records the friends that a user has placed into his friend lists. Its fields are listed in Table 8-10. Queries to this table will only return data the current user is allowed to see (i.e., you can’t request friendlists for users other than the current loggedinuser). More information about this table, including an up-to-date listing of fields, can be found at http://wiki.developers.facebook.com/index.php/Friendlist_member_(FQL).
Table 8-10. friendlist_member table fields
Name
Type
Index
Description
flid
int
•
flid (friendlist ID) of the friend list. You can only query for flids owned by the current loggedinuser.
uid
int
uid (user ID) of the friend that the current loggedinuser has placed in the friend list.
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
If you’d rather use the API to access friendlist_members, try the Friends.getLists() method.
Retrieving a User’s Friend Lists
Problem
I need to retrieve a specific user’s friend lists using FQL.
Solution
SELECT flid, name FROM friendlist WHERE owner = $uid;
Discussion
You can run this query only when uid is the current loggedinuser.
Retrieving a Specific Friend List
Problem
I need to retrieve a specific friend list from a specific user using FQL.
Solution
SELECT flid, name FROM friendlist WHERE name = $name AND owner = $user;
Discussion
You can run this query only when uid is the current loggedinuser.
Retrieving Friends in Friend Lists
Problem
I need to use FQL to retrieve the friends that specific users have put in their friend lists.
Solution
You can pretty easily find all of the friends that the current loggedinuser has put into friend lists:
SELECT flid, uid FROM friendlist_member WHERE flid IN
(SELECT flid FROM friendlist WHERE owner = $uid)
Discussion
You can run this query only when uid is the current loggedinuser.
Retrieving Friends in a Specific Friend List
Problem
I need to retrieve the friends from a specific user’s specific friend list using FQL.
Solution
SELECT name FROM user WHERE uid IN (SELECT uid FROM friendlist
_member WHERE flid IN (SELECT flid FROM friendlist WHERE name = $name
AND owner = $user));
Discussion
This will work only when user is the current loggedinuser.
Groups Table
Problem