forthrin
forthrin

Reputation: 2777

Graph request for "is X my friend"?

Does the Graph API provide a way to check if a certain User ID is my friend? (Other than downloading my entire friend list and scanning through it?)

The Photo tagging function does not allow tagging of users who are not friends, so evidently this must be checked in advance.

Upvotes: 1

Views: 73

Answers (2)

Joachim Isaksson
Joachim Isaksson

Reputation: 180877

If you want to do it using the Graph API and not FQL, you can do it by asking Facebook about a person's friends, and filter the response to your UID only;

/<a's uid>?fields=friends.uid(<your uid>).fields(id)

...will return your id if and only if you're a's friend.

As an example, if your UID is 12345678 and want to see if Mark Zuckerberg has you on his friend list, you'd request;

/112845672063384?fields=name,friends.uid(12345678).fields(id)

Upvotes: 2

Viren Rajput
Viren Rajput

Reputation: 5726

This might be #hacky solution, but it works.

Using FQL to check whether a particular user ID is your friend,

>> SELECT uid2 FROM friend WHERE uid1 = <your uid> and uid2 = <your friends uid>

This will return, your friends uid if he/she is your friend. Or it will return an empty array if not. (its tested)

Upvotes: 2

Related Questions