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

2

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?

Decosta answered 19/1, 2012 at 18:54 Comment(1)
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?Decosta
G
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.

Garter answered 19/1, 2012 at 19:5 Comment(2)
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.Decosta
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.Prolongate
C
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)
Croteau answered 19/1, 2012 at 19:6 Comment(1)
Thanks Gazler. I ended up using the following call: Koala::Facebook::GraphAPI.new(oauth_access_token).get_connections(user1_id, "friends/#{user2_id}").empty?Decosta

© 2022 - 2024 — McMap. All rights reserved.