react-native-google-signin / google-signin

Google Sign-in for your React Native applications
https://react-native-google-signin.github.io/
MIT License
3.19k stars 879 forks source link

I am not getting user's Birthday #1254

Closed RNvivekvision closed 6 months ago

RNvivekvision commented 6 months ago

import React, { useEffect, useState } from 'react'; import { Image, StyleSheet, Text, View } from 'react-native'; import auth from '@react-native-firebase/auth'; import { GoogleSignin } from '@react-native-google-signin/google-signin'; import { RNButton, RNLoader } from './Common'; import { AccessToken, LoginManager } from 'react-native-fbsdk-next';

const webClientId = webClientId; const iosClientId = iosClientId;

const App = () => { const [State, setState] = useState({ isLoading: false, User: null, });

useEffect(() => { init(); }, []);

const init = async () => { setState(p => ({ ...p, isLoading: true })); GoogleSignin.configure({ scopes: [ 'https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/user.birthday.read', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/drive.readonly', ], webClientId: webClientId, offlineAccess: false, iosClientId: iosClientId, }); setState(p => ({ ...p, isLoading: false })); };

const onGooglePress = async () => { setState(p => ({ ...p, isLoading: true })); try { // Check if your device supports Google Play await GoogleSignin.hasPlayServices(); const signin = await GoogleSignin.signIn(); const credential = auth.GoogleAuthProvider.credential(signin.idToken); const google = await auth().signInWithCredential(credential); console.log( 'onGooglePress -> ', JSON.stringify({ google, signin, credential }, null, 2), ); setState(p => ({ ...p, User: google })); } catch (e) { console.error('Error onGooglePress -> ', e); } finally { setState(p => ({ ...p, isLoading: false })); } };

const onLogout = async () => { setState(p => ({ ...p, isLoading: true })); try { await auth().signOut(); setState(p => ({ ...p, User: null })); } catch (e) { console.error('Error onLogout -> ', e); } finally { setState(p => ({ ...p, isLoading: false })); } };

return (

{State.User ? ( <> {`Hello, ${State.User?.user?.displayName}`} {`Email: ${State.User?.user?.email}`} {`Birthday: ${State.User?.user?.displayName}`} ) : ( )}

); };

const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', justifyContent: 'center', alignItems: 'center', }, name: { fontSize: 20, fontWeight: 'bold', color: '#000', }, image: { width: 200, height: 200, borderRadius: 100, }, });

export default App;

Repository with code that reproduces the issue

Expected Behavior

Actual Behavior

{ "google": { "additionalUserInfo": { "profile": { "at_hash": "XliPQTCq8muo_U-fUggVOw", "exp": 1709883711, "azp": "871448389881-qkfdrpelbjps7b1af1jljh4dnk8k5j6i.apps.googleusercontent.com", "nonce": "76kKsT5sEeF_GtVNqPWTcQwNzLETfDPa-Leb4flvEUQ", "picture": "https://lh3.googleusercontent.com/a/ACg8ocKayjEsrqPl1scTvPkPrnBlzJj3Y4NcqZmkZDtPT875=s96-c", "name": "user user", "email_verified": true, "aud": "871448389881-dtndb5nq7b3ivl0n1qjg134iu61eh0jd.apps.googleusercontent.com", "family_name": "user", "locale": "en-GB", "given_name": "user", "iss": "https://accounts.google.com", "sub": "103352901751644267865", "iat": 1709880111, "email": "user@gmail.com" }, "username": null, "providerId": "google.com", "isNewUser": false }, "user": { "displayName": "user user", "multiFactor": { "enrolledFactors": [] }, "isAnonymous": false, "emailVerified": true, "providerData": [ { "email": "user@gmail.com", "providerId": "google.com", "uid": "103352902741644267865", "photoURL": "https://lh3.googleusercontent.com/a/ACg8ocKayjEsrqPl1scTvPkPrnBlzJj3Y4NcqZmkZDtPT875=s96-c", "displayName": "user user" } ], "uid": "y51iamG5csTXESi0vq2YhoYlvbX2", "email": "user@gmail.com", "refreshToken": "AMf-vBwELeXNMgWO-SGVzuydSDy2oUuXyPDqI9lAiRdA6p94ItGiCIemgzuauBmWsjYib_MJ161fBwPn-fRzsSkSoxYB0IDY8pYNzh4U-YQfC50TPe3PcoH9Dq6YOm-945Oa0eJDeHmCfLJKyiLIROSZGo-7wV8GIuhGfbGRQC9MH7j165aqDPKc8xtTU22u2rr020SAtPHfwsXDtoEQ39w03USBk-ZmjYwui3meVhfW3LmckJ8bw5TXc-Tk1gsVGmOE3Yoh7gCs42KeZmrpi6BYa5Uhs5Kd0XDyXT94biWgK_fq4z2Xu2DbsRyOWpSJpZwQ0C5ta4ulkZZxDiwvuVytkpoqXQ3Qe3VV5L9fIXo8jqxSHF-iePExMpzux_HGYGGANXnmEE0sSIR9KXe1HiZrqHaDS-PE_ayp8nqmtopap1kACjc1g0Tuzx4MOVX7iK4pwUstPyKF", "tenantId": null, "phoneNumber": null, "photoURL": "https://lh3.googleusercontent.com/a/ACg8ocKayjEsrqPl1scTvPkPrnBlzJj3Y4NcqZmkZDtPT875=s96-c", "metadata": { "creationTime": 1709805684941, "lastSignInTime": 1709880112746 }, "providerId": "firebase" } }, "signin": { "idToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjA4YmY1YzM3NzJkZDRlN2E3MjdhMTAxYmY1MjBmNjU3NWNhYzMyNmYiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiI4NzE0NDgzODk4ODEtcWtmZHJwZWxianBzN2IxYWYxamxqaDRkbms4azVqNmkuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiI4NzE0NDgzODk4ODEtZHRuZGI1bnE3YjNpdmwwbjFxamcxMzRpdTYxZWgwamQuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMDMzNTI5MDE3NTE2NDQyNjc4NjUiLCJlbWFpbCI6InZpdmVrLnZpc2lvbjIwMjRAZ21haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImF0X2hhc2giOiJYbGlQUVRDcThtdW9fVS1mVWdnVk93Iiwibm9uY2UiOiI3NmtLc1Q1c0VlRl9HdFZOcVBXVGNRd056TEVUZkRQYS1MZWI0Zmx2RVVRIiwibmFtZSI6IlZpdmVrIEdob2RhZHJhIiwicGljdHVyZSI6Imh0dHBzOi8vbGgzLmdvb2dsZXVzZXJjb250ZW50LmNvbS9hL0FDZzhvY0theWpFc3JxUGwxc2NUdlBrUHJuQmx6SmozWTROY3FabWtaRHRQVDg3NT1zOTYtYyIsImdpdmVuX25hbWUiOiJWaXZlayIsImZhbWlseV9uYW1lIjoiR2hvZGFkcmEiLCJsb2NhbGUiOiJlbi1HQiIsImlhdCI6MTcwOTg4MDExMSwiZXhwIjoxNzA5ODgzNzExfQ.vBiqLcZeCY_fpV2b71BK7wlFXJfIQGUNE8yjmxD6WuvOKCpY9wlOaUnoC74dMxYCegRQC-PUnDPGTy-fzfMcP7ptbZoP3a0yZQ7mhtYbj2ljBTmkTo2sTvH67BUVHtp4rUbww_aoAolNt1WcGG3ml_FK0H0C0sOu-wsAhWLt9OvrmN7TieQqMT6kmq2oaFnv737dqz95E8ITBggJSgJO3rq_ZP8ugcdxO_S0sWIwkhN3G5bMorCi3mtrFlzqetbuAUZNCzrrMbu8OQxGz2sSkFXVhJRaIfraKbCYr8P5DhVcBHIwXZI7D5I4WKNV-Gsl1oljTwVKiCQHb5J-BotsJA", "serverAuthCode": "4/0AeaYSHBi7m7S5KbsU8M9WT-W4jQ_YLoujnAvdUuaYX5PQphQFAIfKxzi-UO4DawY8K7g", "scopes": [ "https://www.googleapis.com/auth/user.birthday.read", "https://www.googleapis.com/auth/drive.readonly", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile" ], "user": { "photo": "https://lh3.googleusercontent.com/a/ACg8ocKayjEsrqPl1scTvPkPrnBlzJj3Y4NcqZmkZDtPT875=s120", "givenName": "user", "familyName": "user", "name": "user user", "email": "user@gmail.com", "id": "103352901751644267865" } }, "credential": { "token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjA4YmY1YzM3NzJkZDRlN2E3MjdhMTAxYmY1MjBmNjU3NWNhYzMyNmYiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiI4NzE0NDgzODk4ODEtcWtmZHJwZWxianBzN2IxYWYxamxqaDRkbms4azVqNmkuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiI4NzE0NDgzODk4ODEtZHRuZGI1bnE3YjNpdmwwbjFxamcxMzRpdTYxZWgwamQuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMDMzNTI5MDE3NTE2NDQyNjc4NjUiLCJlbWFpbCI6InZpdmVrLnZpc2lvbjIwMjRAZ21haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImF0X2hhc2giOiJYbGlQUVRDcThtdW9fVS1mVWdnVk93Iiwibm9uY2UiOiI3NmtLc1Q1c0VlRl9HdFZOcVBXVGNRd056TEVUZkRQYS1MZWI0Zmx2RVVRIiwibmFtZSI6IlZpdmVrIEdob2RhZHJhIiwicGljdHVyZSI6Imh0dHBzOi8vbGgzLmdvb2dsZXVzZXJjb250ZW50LmNvbS9hL0FDZzhvY0theWpFc3JxUGwxc2NUdlBrUHJuQmx6SmozWTROY3FabWtaRHRQVDg3NT1zOTYtYyIsImdpdmVuX25hbWUiOiJWaXZlayIsImZhbWlseV9uYW1lIjoiR2hvZGFkcmEiLCJsb2NhbGUiOiJlbi1HQiIsImlhdCI6MTcwOTg4MDExMSwiZXhwIjoxNzA5ODgzNzExfQ.vBiqLcZeCY_fpV2b71BK7wlFXJfIQGUNE8yjmxD6WuvOKCpY9wlOaUnoC74dMxYCegRQC-PUnDPGTy-fzfMcP7ptbZoP3a0yZQ7mhtYbj2ljBTmkTo2sTvH67BUVHtp4rUbww_aoAolNt1WcGG3ml_FK0H0C0sOu-wsAhWLt9OvrmN7TieQqMT6kmq2oaFnv737dqz95E8ITBggJSgJO3rq_ZP8ugcdxO_S0sWIwkhN3G5bMorCi3mtrFlzqetbuAUZNCzrrMbu8OQxGz2sSkFXVhJRaIfraKbCYr8P5DhVcBHIwXZI7D5I4WKNV-Gsl1oljTwVKiCQHb5J-BotsJA", "providerId": "google.com" } }

Environment

Please provide

System: OS: macOS 14.3.1 CPU: (16) x64 Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz Memory: 51.40 MB / 16.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 20.11.1 path: /usr/local/bin/node Yarn: version: 1.22.21 path: /usr/local/bin/yarn npm: version: 10.2.4 path: /usr/local/bin/npm Watchman: version: 2024.01.22.00 path: /usr/local/bin/watchman Managers: CocoaPods: version: 1.14.3 path: /usr/local/bin/pod SDKs: iOS SDK: Platforms:

vonovak commented 6 months ago

Hello and thanks for asking, you need to query Google's people api to get additional information: https://developers.google.com/people/api/rest/v1/people/get

Thank you 🙂

RNvivekvision commented 6 months ago

@vonovak Thank you very much for the help.