在 Flutter 中使用 google_sign_in 时获取 idToken 'null'

fre*_*hme 7 google-signin flutter

我正在使用 google_sign_in 插件。

它运行良好。但我有一个问题。

我需要将 idToken 发送到后端服务器来验证用户。

但 Google 登录响应中的 IdToken 为空。

代码很简单

  final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
  final GoogleSignInAuthentication googleAuth =
      await googleUser.authentication;
  print("Printing google user info");
  print(googleAuth.accessToken);
  print(googleAuth.idToken);
  print(googleUser.displayName);
Run Code Online (Sandbox Code Playgroud)

其他属性具有正确的值。但 idToken 为空

我用谷歌搜索了这个并说我需要网络客户端 ID。

所以我做了

final _googleSignIn = GoogleSignIn(clientId: webClientId);

你们能帮忙吗?

我错过了什么吗?

moh*_*esR 10

编辑 2023 年 12 月 27 日

使用flutter CLI

https://firebase.google.com/docs/flutter/setup


我面对这个问题两天了,终于。(就我而言)这个解决方案有效。

https://firebase.flutter.dev/docs/installation/android#installing-your-firebase-configuration-file

  • 这并没有为我解决这个问题,我已经设置了这些依赖项,但仍然遇到了这个错误 (2认同)
  • 这对我来说也不起作用。给定的网页链接无效 (2认同)