Facebook Graph API - How to Get Sex from a Public Profile

I need to get gender from a Facebook user from his public profile via the Facebook Graph API.

Unfortunately, it does not always work. See the following 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 over the Internet, it works, and I even see the gender. (Go to the section "About us / Contacts and basic information"). I logged in with my personal account and not this user's friend! http://www.facebook.com/10152133878666403

What is the problem? Is this a problem with a request or security feature from Facebook?

UPDATE:

I can do a workaround like this, but only if I logged in with my browser:

Take app_scoped_user_id and get your Facebook username from the redirect URL when you open 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 alias?

+6
source share
3 answers

As already mentioned in the comments of the Facebook employee, this is simply not possible, because it is not supported for obtaining a โ€œgenderโ€ or real Facebook user ID.

Possible workarounds:

  • use the gender api (e.g. genderize.io ) to get the gender based on the first name.
  • clear gender information from Facebook (must be registered on the network) from the user about the page.
+5
source

User gender is returned only with API version 1.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 good gender verification api.

+3
source

The best way to check this is with the facebook api chart under develoers.facebook.com => tools and support => GUI API.

 $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 friends with a name and gender, you can go through the loop and set a condition inside the loop to separate male and female friends.

Hope this helps

read this article for more information

Getting Facebook Facebook Friends

+2
source

Source: https://habr.com/ru/post/972800/


All Articles