本项目中尚未使用People Api

问题描述 投票:0回答:1

我正在尝试在 Flutter Web 项目中使用 google 进行身份验证,我有这样的东西

  final GoogleSignIn _googleSignIn = GoogleSignIn(
      scopes: <String>[
          'email',
      ],
  );

  Future<void> test() async {
      try {
          await _googleSignIn.signOut();
          GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
      } catch (e) {
          print(e);
      }
  }

我刚刚这样做,就会出现 Google 弹出窗口,但是当我选择帐户时,我收到此响应

{"access_token":"<redacted>","token_type" 
:"Bearer","expires_in":3598,"scope":"email profile 
https://www.googleapis.com/auth/userinfo.profile openid
https://www.googleapis.com/auth/userinfo.email","authuser":"0","prompt":"none"}

还有这个错误

[GSI_LOGGER-TOKEN_CLIENT]: Trying to set gapi client token.
[GSI_LOGGER-TOKEN_CLIENT]: The OAuth token was not passed to gapi.client, since the 
gapi.client library is not loaded in your page.

ClientException: {
 "error": {
 "code": 403,
 "message": "People API has not been used in project proyectId before or it is 
disabled. Enable it by visiting
https://console.developers.google.com/apis/api/people.googleapis.com/overview? 
project=proyectId then retry. If you
enabled this API recently, wait a few minutes for the action to propagate to our 
systems and retry.",
"status": "PERMISSION_DENIED",
"details": [
  {
    "@type": "type.googleapis.com/google.rpc.Help",
    "links": [
      {
        "description": "Google developers console API activation",
        "url": 
"https://console.developers.google.com/apis/api/people.googleapis.com/overview? 
 project=proyectId"
      }
    ]
  },
  {
    "@type": "type.googleapis.com/google.rpc.ErrorInfo",
    "reason": "SERVICE_DISABLED",
    "domain": "googleapis.com",
    "metadata": {
      "service": "people.googleapis.com",
      "consumer": "projects/proyectId"
    }
   }
  ]
  }
 }

我已经在index.html中添加了元标记

    <meta name="google-signin-client_id" content="googleProyectId" />

所以我不知道我是否遗漏了一些东西

flutter google-oauth google-signin google-people-api
1个回答
0
投票

阅读文档,我意识到在 Flutter Web 中,signIn 方法不应该使用并且将被弃用,最好混合使用signInSilently 方法,但如果用户关闭一次并且不再打开它有时会失败(我想是为了安全)。

他们推荐的另一种方法是使用他们的 renderButton,它可以工作,但不可自定义。

就我而言,我使用的是 Firebase,所以我这样做了

FirebaseAuth.instance.signInWithPopup(GoogleAuthProvider());

当然我需要有以前的 firebase 配置。

但是,我认为他们应该改进signIn()的真正替代方案

© www.soinside.com 2019 - 2024. All rights reserved.