Arn*_*nav 5 dart google-oauth google-signin flutter
我有一个方法用来获取用户的基本信息,如生日、性别和电话号码,我现在知道如何在 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');
}
}
Run Code Online (Sandbox Code Playgroud)
小智 7
我希望这个答案能帮助你。您可以尝试在 GoogleSignIn() 方法中添加范围,如下所示
GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: [
'email',
'https://www.googleapis.com/auth/contacts.readonly',
],
);
Run Code Online (Sandbox Code Playgroud)
您可以根据您想要访问的信息调整范围。这是您可以使用Google Scopes 列表的完整范围列表的链接
请注意,某些范围需要应用程序验证,上面的链接中提到了这一点。
| 归档时间: |
|
| 查看次数: |
5010 次 |
| 最近记录: |