higherDefender
higherDefender

Reputation: 1561

Get friend's gender in a Facebook application

While developing a Facebook application I got the friendlist of a user by

$friends = $facebook->api('/me/friends');

But I only got to know the name and Facebook Ids of the friends : http://developers.facebook.com/docs/reference/api/FriendList

Is there any way to get the gender of a friend?

One way to do so is to get the user's gender (since it is publicly available) given the user's facebook Id (which I have got using the friend list)

Is it really possible to do the above thing.

If not is there any other way?

for reference : http://developers.facebook.com/docs/reference/api/user

Upvotes: 2

Views: 7439

Answers (2)

goker
goker

Reputation: 2720

A quick way with Graph API

$facebook->api('me/friends?fields=id,name,gender,installed&access_token=[ACCESS_TOKEN]");

Upvotes: 4

Thomas
Thomas

Reputation: 3044

http://developers.facebook.com/docs/reference/api/FriendList = a persons fiend lists (plural) - eg: Limited Profile

What you want to do is get the ID from graph.facebook.com/me/firends and then do a graph.facebook.com/ID for the gender. But of course that ends up being a lot of requests if you need it for all of their friends.

For those cases you can use FQL query: http://developers.facebook.com/docs/reference/fql/

You can adopt following query from their documentation:

SELECT uid, name, pic_square FROM user WHERE uid = me() OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me())

Here name and gender of the current users friends:

SELECT uid, name, sex FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())

Upvotes: 2

Related Questions