Google SignIn SDK is failing by throwing error, A non-recoverable sign in failure occurred -catch error: React Native
我一直在尝试将社交登录集成到我的react本机项目中,在该项目中我能够成功进行Facebook登录,但是无法登录到google。 react-native-google-signin库用于google。
我使用的代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | 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'); } } }; |
错误响应:
1 | Message: A non-recoverable sign in failure occurred -catch error |
我知道,我回答这个问题很晚了。我只是遇到了同样的问题,花了将近4-5个小时来解决这个问题。
我发现的解决方案:
"当我在Firebase上添加支持电子邮件后,它开始工作"
我认为这不是应用程序或配置问题。可能是应解决的Firebase问题,文档中无处可查。
在android文件夹中运行
以下是
-
cd ./android
对于我来说,我已经使用了测试应用程序的程序包名称(例如com.loginTest)。在使程序包名称唯一之后,我就可以解决此问题!
那是由于clientId。
在Google Developer Console中,当您为webClientID配置项目时,而不是创建一个新项目,而是选择一个现有项目,即先创建该项目,然后选择该项目以创建凭据。首先创建一个新项目,如下图所示
然后从列表中选择该项目以创建凭据
对我有用。
然后登录配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16GoogleSignin.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: ''
})
在firebase中添加支持电子邮件,它将开始工作
您需要添加
support email 。
为此请转到:- - 转到console.developer.google.com
- 选择项目。
- 转到项目设置
- 在常规标签下,向下滑动以添加支持电子邮件。在那添加您的电子邮件。
- 转到console.developer.google.com
- 选择项目。
- 转到凭据。
- 切换到O验证同意屏幕。
- 更改应用名称并填写电子邮件ID(可选)
- 保存在底部
-
Enable OAuth on
https://console.developers.google.com - Copy and paste your SH1 while enabling
- Enable Google sign in on firebase authentication
- Use Oauth Client_Id instead of your WebClient ID
此修复程序还可以帮助您:
立即尝试登录,它应该可以运行。
我搜索并遇到以下步骤