Google SignIn SDK 因抛出错误而失败,发生不可恢复的登录失败 -catch 错误:React Native

UJ *_*dia 10 javascript android google-login reactjs react-native

我一直在尝试将社交登录集成到我能够成功登录 facebook 的本机项目中,但无法登录到谷歌。react-native-google-signin库用于谷歌。

我用过的代码。

componentDidMount() {
GoogleSignin.hasPlayServices({ autoResolve: true }).then(() => {
// play services are available. can now configure library
}).catch((err) => {

console.log("Play services error", err.code, err.message);
})
GoogleSignin.configure({
scopes: ["https://www.googleapis.com/auth/drive.readonly"], // what API you want to access on behalf of the user, default is email and profile
// iosClientId: <FROM DEVELOPER CONSOLE>, // only for iOS
webClientId: "xxx", // client ID of type WEB for your server (needed to verify user ID and offline access)
// offlineAccess: true // if you want to access Google API on behalf of the user FROM YOUR SERVER
//hostedDomain: '' // specifies a hosted domain restriction
//forceConsentPrompt: true // [Android] if you want to show the authorization prompt at each login
//accountName: '' // [Android] specifies an account name on the device that should be used
})
.then(() => {
// you can now call currentUserAsync()
});
    _signIn = async () => {

        try {

            await GoogleSignin.hasPlayServices(

              )

          const userInfo = await GoogleSignin.signIn();
          console.log('User Info --> ', userInfo);
          this.setState({ userInfo });
        } catch (error) {

          console.log('Message', error.message);
          if (error.code ===  statusCodes.SIGN_IN_CANCELLED) {
            console.log('User Cancelled the Login Flow');
          } else if (error.code === statusCodes.IN_PROGRESS) {
            console.log('Signing In');
          } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
            console.log('Play Services Not Available or Outdated');
          } else {
            console.log('Some Other Error Happened');
          }
        }
      };
Run Code Online (Sandbox Code Playgroud)

错误响应:

Message: A non-recoverable sign in failure occurred -catch error
Run Code Online (Sandbox Code Playgroud)

Ash*_*wal 17

我知道,我回答这个问题已经很晚了。我刚刚遇到了同样的问题,花了将近 4-5 个小时来解决这个问题。我找到的解决方案:“当我在 Firebase 上添加支持电子邮件时它开始工作”我认为这不是应用程序或配置问题。这可能是一个应该报告的 firebase 问题,并且在文档中没有任何地方。

Firebase 设置的屏幕截图

  • 我已经添加了一封支持电子邮件。:( (3认同)

the*_*ron 9

关注这里

  • cd ./android && ./gradlew 签名报告
  • 获取任务 :app:signingReport、变体:debugAndroidTest、配置:debug 的 SHA1
  • 在项目设置、Android 应用程序下的 Firebase 控制台中更新它,添加 SHA1
  • 下载google-services.json,放入./android/app
  • 转到“身份验证”,然后转到“登录方法”,然后按“Google”
  • 获取网络客户端 ID 并将其用于您的 GoogleSignin.configure({ webClientId: ... });
  • 此 Web 客户端 ID 应与https://console.developers.google.com/apis/credentials?project= <your_project_id> -> Credentials -> OAuth 2 Client ID -> Web Client中列出的相同


Sou*_*era 9

Apk 链接https://drive.google.com/file/d/1FNFBX-M7PQC6ShCC3KSuOH2E57YGPj6H/view?usp=sharing

 go to android folder  ./gradlew signingReport Take the SHA1 of Task

 :app:signingReport, Variant: debugAndroidTest, Config: debug Update

add fingure print sha1 in your project inside firebae.console.google.com
Run Code Online (Sandbox Code Playgroud)

并在您的项目中再次下载 google-service.json 文件

在此输入图像描述

在此输入图像描述

在此输入图像描述

[错误:发生不可恢复的登录失败]

1. add support email to solve this error 
2. and wait 5 minutes your google login will be working fine
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Tap*_*bhi 5

gradlew signingReport在 android 文件夹中运行并检查列出的所有sha1,如果您使用的是 firebase,请确保将列表中找到的所有不同sha1添加到 firebase 项目中,然后再次下载 google-services.json 将其替换为旧的在您的项目中再次运行cd android && gradlew clean并构建您的项目


小智 4

这是由于 clientId 造成的。在 google 开发者控制台中,当您为 webClientID 配置项目时,不要创建新项目,而是选择现有项目,即先创建项目,然后选择它来创建凭据。

首先创建一个新项目,如下图所示 以这种方式创建一个项目

然后从列表中选择该项目来创建凭据在此输入图像描述

这对我有用。

并进行登录配置

GoogleSignin.hasPlayServices({ autoResolve: true }).then(() => {

})
.catch((err) => {
      console.log("Play services error", err.code, err.message);
})

GoogleSignin.configure({
     scopes: ["https://www.googleapis.com/auth/userinfo.profile"],//scopes as you need 
     webClientId: "***(Your clientId)",
     //iosClientId: <FROM DEVELOPER CONSOLE>, // only for iOS 
     //offlineAccess: true, //(give it true if you need serverAuthCode i.e cross client authorisation)
     //hostedDomain: '' 
     //forceConsentPrompt: true // [Android] if you want to show the authorization prompt at each login
     //accountName: ''
})
Run Code Online (Sandbox Code Playgroud)