6

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?

Aaron
  • 13,349
  • 11
  • 66
  • 105
  • Thanks for the answers all. I ended up going with a combination of the two: Koala::Facebook::GraphAPI.new(oauth_access_token).get_connections(user1_id, "friends/#{user2_id}").empty? – Aaron Jan 20 '12 at 20:16

2 Answers2

7

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.

Andy Muth
  • 1,429
  • 8
  • 4
  • Thanks Andy! I figured this out last night and didn't update the question. I'm wasn't able to find a method for this in Koala (since there's no documentation on the args param) but it might work with that. – Aaron Jan 20 '12 at 20:12
  • Seriously, It does not work. It returns always empty array in `data` even if a user is friend. And it returns total count of my friends. – shashwat Mar 18 '15 at 05:04
1

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)
Gazler
  • 83,029
  • 18
  • 279
  • 245
  • Thanks Gazler. I ended up using the following call: Koala::Facebook::GraphAPI.new(oauth_access_token).get_connections(user1_id, "friends/#{user2_id}").empty? – Aaron Jan 20 '12 at 20:13