首页 > 解决方案 > 在 Ionic 4 上使用 Google 的 Oauth2 进程卡在“请稍候”

问题描述

我有一个从 github.com/ionicthemes/ionic-google-login 粘贴的教程 Ionic 4 应用程序我有以下代码被调用:

this.googlePlus.login({
      'scopes': '', // optional - space-separated list of scopes, If not included or empty, defaults to `profile` and `email`.
      'webClientId': environment.googleWebClientId, // optional - clientId of your Web application from Credentials settings of your project - On Android, this MUST be included to get an idToken. On iOS, it is not required.
      'offline': true, // Optional, but requires the webClientId - if set to true the plugin will also return a serverAuthCode, which can be used to grant offline access to a non-Google server
    }).then(user => {
      console.log('+++ user is:', user);
    }, err => {
      console.log("+++ google login error:", err);
    })

既不成功,也不打印错误消息。我一直在等待 Google 的回复。

我这样做了:keytool -exportcert -keystore path-to-debug-or-production-keystore -list -v并在 console.developers.google.com 上添加了 sha1 指纹。包名匹配(com.tgm_ionic),我选择了 oauth2 android flow。

额外信息:这曾经在浏览器平台上工作,但在 android 模拟器上会失败,错误 10,即“无效观众”。所以我创建了新的凭据以从浏览器平台移动到 android 平台(仍然是 oauth2),现在我遇到了这个问题。这里的目标是能够在 android 上登录,而不是在浏览器中。

标签: oauth-2.0ionic4

解决方案


验证您的 webClientId 是否正确。您可以在 Google API 控制台中引用它,然后查看凭据并检查您的 OAuth 2.0 客户端 ID。当需要 Web 客户端 ID 时,通常使用这些混合应用程序的人会使用 android 密钥。


推荐阅读