How to check if a FACEBOOK ID is male or female

I was wondering if we can check the gender of facebook users using the facebook id.

+4
source share
2 answers

You did not specify which SDK you use, I assume that you are using PHP
below is the php code, and I think that if you can use any other SDK, you can also use the code below with some necessary changes and yes, this code works fine, I tested this code before answering here :)

<?php //get the user gender $user_id = $facebook->getUser(); $user_profile = $facebook->api('/me','GET'); $user_gender = $user_profile['gender']; echo "Gender: " . $user_gender; ?> 

You need the permission user_about_me if the user gender is not public, and you can also get the gender of friends of users using the friends_about_me permission if the user has set it public

below - my authorization code, which must be entered into your authorization code, use the code above in the field

  $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($canvas_page) . ("&scope=email,read_stream,publish_stream,offline_access,publish_actions,user_about_me,fiends_about_me&response_type=token" 
+1
source

Yes, you can use the Graph API to query the user, here is my object, as you can see, I have a property called gender, I believe that this property can be hidden if the user configured it as such, so never assume what is the answer ...

It also requires the target user to give you access to the basic information of your application.

 { "id": "754124803", "name": "Daniel Phillips", "first_name": "Daniel", "last_name": "Phillips", "link": "https://www.facebook.com/daniel.jp", "username": "daniel.jp", "gender": "male", "timezone": 0, "locale": "en_GB", "verified": true, "updated_time": "2012-02-04T16:00:42+0000", "type": "user" } 

If you just want to check this out, use the Graph API: https://developers.facebook.com/tools/explorer/

+6
source

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


All Articles