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

Checking Whether Two Users are Friends

Problem

I need to check to see whether two users are friends using FQL.

Solution

If this query returns a result, user1 and user2 are friends:

SELECT uid1 FROM friend WHERE uid1 = $user1 AND uid2 = $user2;

Discussion

There are no privacy restrictions on this query in terms of errors, but you will get back an empty set if the current loggedinuser isn’t allowed to see the friends for one of the two users.

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