It took me a day figuring out this. Hope it will help others .
- 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"}
/>
In your JSON data you will get googleId and accessToken.
JSON data
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/