How to get additional scopes from GoogleSignIn in Flutter?

Viewed 2272

I have a method which I am using to get a users basic info like birthday, gender & phone number and I'm now sure how to implement it in Flutter?

 void signInWithGoogle(context) async {
final GoogleSignIn _googleSignIn = GoogleSignIn();
    try {
      final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
      final GoogleSignInAuthentication googleAuth =
          await googleUser.authentication;
      final AuthCredential credential = GoogleAuthProvider.credential(
        accessToken: googleAuth.accessToken,
        idToken: googleAuth.idToken,
      );
      final User user = (await _auth.signInWithCredential(credential)).user;
      
    } catch (error) {
      print('Google error: $error');
    }
  }
1 Answers

I hope this answer will help you. You can try adding a scope in your GoogleSignIn() method like that

GoogleSignIn _googleSignIn = GoogleSignIn(
  scopes: [
    'email',
    'https://www.googleapis.com/auth/contacts.readonly',
  ],
);

And you can adjust your scopes based on the information you want to access. And this is the link to the full list of scopes you can use Google Scopes list

Note that some scopes will require app verification and it's mentioned in the above link.

Related