簡體   English   中英

Google SignIn SDK 因拋出錯誤而失敗,出現不可恢復的登錄失敗 - 捕獲錯誤:React Native

[英]Google SignIn SDK is failing by throwing error, A non-recoverable sign in failure occurred -catch error: React Native

我一直在嘗試將 Social 登錄集成到我的 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');
          }
        }
      };

錯誤響應:

Message: A non-recoverable sign in failure occurred -catch error

我一直在嘗試將社交登錄集成到我的React Native項目中,在該項目中我能夠成功進行Facebook登錄,但是無法登錄到google。 react-native-google-signin庫用於google。

我使用的代碼。

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');
          }
        }
      };

錯誤響應:

Message: A non-recoverable sign in failure occurred -catch error

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

並在您的項目中再次下載 google-service.json 文件

在此處輸入圖片說明

在此處輸入圖片說明

在此處輸入圖片說明

我一直在嘗試將社交登錄集成到我的React Native項目中,在該項目中我能夠成功進行Facebook登錄,但是無法登錄到google。 react-native-google-signin庫用於google。

我使用的代碼。

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');
          }
        }
      };

錯誤響應:

Message: A non-recoverable sign in failure occurred -catch error

我一直在嘗試將社交登錄集成到我的React Native項目中,在該項目中我能夠成功進行Facebook登錄,但是無法登錄到google。 react-native-google-signin庫用於google。

我使用的代碼。

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');
          }
        }
      };

錯誤響應:

Message: A non-recoverable sign in failure occurred -catch error

我一直在嘗試將社交登錄集成到我的React Native項目中,在該項目中我能夠成功進行Facebook登錄,但是無法登錄到google。 react-native-google-signin庫用於google。

我使用的代碼。

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');
          }
        }
      };

錯誤響應:

Message: A non-recoverable sign in failure occurred -catch error

我一直在嘗試將社交登錄集成到我的React Native項目中,在該項目中我能夠成功進行Facebook登錄,但是無法登錄到google。 react-native-google-signin庫用於google。

我使用的代碼。

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');
          }
        }
      };

錯誤響應:

Message: A non-recoverable sign in failure occurred -catch error

我一直在嘗試將社交登錄集成到我的React Native項目中,在該項目中我能夠成功進行Facebook登錄,但是無法登錄到google。 react-native-google-signin庫用於google。

我使用的代碼。

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');
          }
        }
      };

錯誤響應:

Message: A non-recoverable sign in failure occurred -catch error

我一直在嘗試將社交登錄集成到我的React Native項目中,在該項目中我能夠成功進行Facebook登錄,但是無法登錄到google。 react-native-google-signin庫用於google。

我使用的代碼。

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');
          }
        }
      };

錯誤響應:

Message: A non-recoverable sign in failure occurred -catch error

我一直在嘗試將社交登錄集成到我的React Native項目中,在該項目中我能夠成功進行Facebook登錄,但是無法登錄到google。 react-native-google-signin庫用於google。

我使用的代碼。

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');
          }
        }
      };

錯誤響應:

Message: A non-recoverable sign in failure occurred -catch error

我一直在嘗試將社交登錄集成到我的React Native項目中,在該項目中我能夠成功進行Facebook登錄,但是無法登錄到google。 react-native-google-signin庫用於google。

我使用的代碼。

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');
          }
        }
      };

錯誤響應:

Message: A non-recoverable sign in failure occurred -catch error

試試這些,不要使用 webClientId 和 offlineAccess: true

GoogleSignin.configure({
     ClientId:
        '48774575517-o9j0crni6shsal3jnoerm1o19pdqkg05.apps.googleusercontent.com',
      
    });

它對我有幫助,我不使用 firebase,googlePlayServicesAuthVersion = "15.0.1",classpath 'com.google.gms:google-services:3.2.1',什么都沒有

只是我安裝

  1. npm i @react-native-google-signin/google-signin
  2. cd android 和 gradlew clean

現在運行應用程序,它應該可以正常工作。

安卓

確保遵循以下指南:

不要忘記生成 SHA-Keys 並在 Firebase 控制台中設置它們

帶模擬器:

在 Android 模擬器上進行測試時,請確保啟用了 GooglePlayServices。 為了證明這一點,請在您的 SignInMethod 中添加更多行:

const signInWithGoogle = async() => {
  // Wrap with try catch 
  try {
    await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true }); // <-- Add this
    const { idToken } = await GoogleSignin.signIn();
    const googleCredential = auth.GoogleAuthProvider.credential(idToken);
    return auth().signInWithCredential(googleCredential);
  } catch (error) {
    // This will show you if GooglePlayServices is missing
    console.log('With high probability, GooglePlayServices are missing on this device');
    return;
  }
}

問題可能在於應用程序名稱,將其更改為隨機(或唯一)名稱(您確定沒有其他人選擇的名稱),或者生成一個具有隨機(或唯一)名稱的新應用程序。

這是因為生成的 React Native 應用程序都帶有相同的 SHA-1 指紋,並且因為 Google 防止在其雲上注冊的兩個不同的 Android 應用程序共享同一對應用程序名稱和 SHA-1 指紋,所以您會收到此錯誤(並且您肯定已經在創建 App 時在 Firebase 控制台上看到了警告。)

資料來源: https://support.googles.ltd/firebase/answer/6401008?hl=en&ref_topic=6399725

在 React Native 應用程序上使用 Google 登錄的完整指南: https://github.com/ubugnu/reactnative-google-signin

我不知道為什么,但是當我用 api 31 創建另一個模擬器時,我在 Android 28 的模擬器上遇到了這個錯誤,錯誤已修復!

如果您的應用程序正在發布:

  • 在項目上,go 到/android ,然后運行./gradlew signingReport
  • 復制 release 和 debugTest 的 SHA1(非常重要)
  • Go 至https://console.firebase.google.com
  • 放置所有 SHA1
  • 下載Google Services JSON 放到android/app
  • 構建您的應用程序並運行!

這對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM