Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out if a user is friends with exactly one other user using Graph API

I'm trying to find out if User A is friends with User B but I don't want User A's entire list of friends. Is there a way, using Koala / the Graph API to simply find out if User A is friends with User B just using User B's Facebook ID?

like image 214
Aaron Avatar asked Jan 19 '12 18:01

Aaron


2 Answers

You can use https://graph.facebook.com/me/friends/{friend's user id}

If they are friends it will return the ID and Name, if not an empty array.

like image 112
Andy Muth Avatar answered Sep 23 '22 16:09

Andy Muth


This can be done easily with FQL.

query = "SELECT uid2 FROM friend WHERE uid1=me() and uid2=FRIEDS ID HERE"

@rest = Koala::Facebook::API.new(oauth_access_token)
# in 1.1 or earlier, use RestAPI instead of API

@rest.fql_query(query) # convenience method

You can test it here if you append an access token.

https://graph.facebook.com/fql?q=SELECT uid2 FROM friend WHERE uid1=me() and uid2=123456

You can also check multiples at one with:

SELECT uid2 FROM friend WHERE uid1=me() and uid2 in (123,1234)
like image 22
Gazler Avatar answered Sep 24 '22 16:09

Gazler