Search code examples
javascriptgoogle-apigoogle-oauthgoogle-authenticationgoogle-data-api

Can you get profile like gender and d.o.b from google signin on a website?


I've added google sign in option on my website where I ask for the user's gender and d.o.b. How can I extract the gender and d.o.b. from the Google Sign-In API?

Is there another method to extract the gender and birthdate. through the Google Sign-In API?

profile.gender() was the function I was trying to use. I was expecting it to return the gender of the user, but it didn't return anything!

the code for the same is

<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark">
</div> 
<script> function onSignIn(googleUser) { // Useful data for your client-side scripts: 
var profile = googleUser.getBasicProfile(); 
console.log("ID: " + profile.getId()); // Don't send this directly to your server! 
console.log('Full Name: ' + profile.getName()); 
console.log('Given Name: ' + profile.getGivenName()); 
console.log('Family Name: ' + profile.getFamilyName()); 
console.log("Image URL: " + profile.getImageUrl()); 
console.log("Email: " + profile.getEmail()); // The ID token you need to pass to your backend: var id_token = googleUser.getAuthResponse().id_token; console.log("I`enter code here`D Token: " + id_token); } 
</script> 
</body>
 </html> 

is there any gender function??


Solution

  • People.get returns a person resource However birthday will only return if the user has it set to public in the sharing settings on their profile.

    It doesnt matter what scope you have set. They have to have set it to public i believe there is a feature request for this from back when google+ was around.

    The same goes for Gender by default a lot of the personal information is set to private a user would have to purposely go and set it to public so that you can see it in the api.

    enter image description here