Facebook Adds New Platform API to Easily Query Mutual Friends

Yesterday, Facebook added a new API call and FQL table to query mutual friend relationships between two users. The concept has been around for years on Facebook, but now applications have access to this same information without having to perform expensive queries on their databases.

As with most data accessed using the API or FQL tables, this information is still held to the Platform’s policy on data usage: in most cases, data may not be stored for more than 24 hours.

Technical Details

Since this API is new, a function doesn’t exist in the official Facebook PHP client yet. If you’d like to take advantage of this API call right away, you can add this code into your facebookapi_php5_restlib.php file. This function requires a session key to work. If you do not have a session key for the users you’re making a comparison on, see below. Included in the code is an example of how to utilize the new call.

One point of interest: the new API call requires an input of two user ID’s to make the comparison. The second parameter, “source_uid”, must be set to the user ID matching the current session key. The first parameter, “target_uid”, can be any user ID even if the “target_uid” is not current friends with the “source_uid” – making this API call powerful.

The API call requires a session key to function correctly (you will receive an error otherwise). However, Facebook is also offereing this data in FQL format under the new standard_friend_info table. According to Facebook, you should only use the FQL table if you do not have access to the session key – otherwise, use the API call as outlined above.