How to get Gender from Public Profile
I need to retrieve the gender from a Facebook user from his public profile via Facebook Graph API.
Unfortunately it is not always working. See these examples:
working: https://graph.facebook.com/1423993568
{
"id": "1423993568",
"gender": "male",
...
}
not working: https://graph.facebook.com/10152133878666403
{
"error": {
"message": "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100
}
}
But when I open the user id directly via web, it works, and I can even see the gender. (Go to "About/Contact and Basic Info") I am logged in with my personal account and not a friend of this user! http://www.facebook.com/10152133878666403
What is the problem? Is it a problem with the request or a security feature from Facebook?
UPDATE:
I can do a workaround like this, but only if I am logged in with my browser:
Take the app_scoped_user_id and get the Facebook username from the redirect URL, when opening this request:
http://www.facebook.com/app_scoped_user_id/10152133878666403
--> https://www.facebook.com/shiffoni
--> https://graph.facebook.com/shiffoni
returns:
{
"id": "669926402",
"first_name": "Shiffoni",
"gender": "female",
"last_name": "Leonhardt",
"locale": "de_DE",
"name": "Shiffoni Leonhardt",
"username": "shiffoni"
}
Any other ideas to get the gender, real userId, or nickname?
As already answered in the comments by a Facebook employee, it is simply not possible, because it is not supported to get the 'gender' or the real Facebook user id.
Possible workarounds:
User gender is returned only with API version v1.0. Unfortunately v1.0 is available until April 30, 2015 https://developers.facebook.com/docs/apps/changelog. http://www.name-gender.com/ is also a quite good api to check gender.
Best Way to check it using facebook graph api under develoers.facebook.com => tools & support =>Graph API Explorer.
$fb = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$fbuser=$fb->api('/me/friends?fields=id,name,gender');
it will give an array of your all friends with name & gender, you can loop through and put a condition inside the loop for separating the male & female friends.
Hope it helps
for more info read this article
Getting Facebook Friends with Gender
链接地址: http://www.djcxy.com/p/32618.html下一篇: 如何从公共档案中获取性别信息