How can I retrieve the gender and phone number and birthdate?
Future<UserCredential> signInWithGoogle() async {
final GoogleSignInAccount? googleUser = await GoogleSignIn(scopes: [
'email',
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/user.phonenumbers.read",
"https://www.googleapis.com/auth/user.birthday.read",
"https://www.googleapis.com/auth/profile.agerange.read"
]).signIn();
final GoogleSignInAuthentication? googleAuth =
await googleUser?.authentication;
final credential = GoogleAuthProvider.credential(
accessToken: googleAuth?.accessToken,
idToken: googleAuth?.idToken,
);
return await FirebaseAuth.instance.signInWithCredential(credential);
}
how i can retrieve gender and phone number and birthdate
thanks for any help
my code is
2
Answers
You cannot get the gender, phone number, and birthdate because the GoogleSignInAccount doesn’t contain such fields. The only fields that are present are, the displayName, email, id, and photoUrl.
To access the data for the scopes you requested, you can check the
scopes
property of theGoogleSignIn
object.There’s an example of this in the pub.dev example tab for the package. Then after the call where the user authorizes access to these scopes, they should be set on the
scopes
property I linked above.