1

I need to get the gender and birthdate of users using the Google Sign-In for Websites.

The info I get from users:

enter image description here

But I cant take the birthdate and gender

I used this guide for reference https://developers.google.com/identity/sign-in/web/build-button

Rahman Haroon
  • 1,088
  • 2
  • 12
  • 36

1 Answers1

1

It took me a day figuring out this. Hope it will help others .

  1. I am using react-google-login.

Adding scope in GoogleLogin:

<GoogleLogin
clientId = 'YOUR CLIENT ID'
buttonText = 'Login'
scope = 'https://www.googleapis.com/auth/user.birthday.read https://www.googleapis.com/auth/user.gender.read https://www.googleapis.com/auth/userinfo.profile'
onSuccess = {handleSuccess}
onFailure = {handleFail}
cookiePolicy = {"single_host_origin"}
/>
  1. In your JSON data you will get googleId and accessToken. JSON data

  2. Then call get function passing these 2 values. You can either use googleId or you can use people/me and add a parameter access_token with the token data.

    
     axios
     .get(`https://people.googleapis.com/v1/people/${googleId}?personFields=birthdays,genders&access_token=${accessToken}`)
     .then((response) => {console.log(JSON.stringify(response, null, 4)); }) //You will get data here
     .catch((error) => {console.warn(JSON.stringify(error, null, 4));});
     

*Note : The birthday should be set public. https://aboutme.google.com/