React native google auth android开发者\u错误代码10 我所做的:

React native google auth android开发者\u错误代码10 我所做的:,android,firebase,react-native,firebase-authentication,google-authentication,Android,Firebase,React Native,Firebase Authentication,Google Authentication,react native init testAuthGoogle&&cd testAuthGoogle&&(cd-android;/gradlew-signingReport)创建新项目并显示SHA1 >任务:应用程序:签名报告 变体:debugAndroidTest 配置:调试 Store:/Users/anand/ws/rn01/testAuthGoogle/android/app/debug.keystore 别名:androiddebugkey MD5:20:F4:61:48:B7:2D

react native init testAuthGoogle&&cd testAuthGoogle&&(cd-android;/gradlew-signingReport)
创建新项目并显示SHA1

>任务:应用程序:签名报告
变体:debugAndroidTest
配置:调试
Store:/Users/anand/ws/rn01/testAuthGoogle/android/app/debug.keystore
别名:androiddebugkey
MD5:20:F4:61:48:B7:2D:8E:5E:5C:A2:3D:37:A4:F4:14:90
SHA1:55:88:11:06:2E:A3:CC:2C:4A:0D:EE:78:76:88:A6:F3:8C:AB:FF:88
SHA-256:FA:C6:17:45:DC:09:03:78:6F:B9:ED:E6:2A:96:2B:39:9F:73:48:F0:BB:6F:89:9B:83:32:66:75:91:03:3B:9C
有效期至:2052年4月30日星期二
将SHA1复制到firebase并创建了android应用程序

google services.json
文件下载到
android/app/google services.json

在android/build.gradle中:

  • 添加了依赖项:
    classpath(“com.google.gms:googleservices:4.3.3”)
在android/app/build.gradle中

  • 应用插件:
    Apply插件:“com.google.gms.google服务”
  • 添加了依赖项
    implementation'com.google.firebase:firebase analytics:17.5.0'
    implementation'com.google.firebase:firebase auth:19.4.0'
已安装的其他依赖项:

npm安装--save@react native firebase/app@react native firebase/auth@react native community/google登录
google services.json
文件复制了
client\u id
,以便在app.js中使用。

app.js中的代码更改

import React, { useEffect, useState } from 'react';
import { SafeAreaView, StyleSheet, ScrollView, View, Text, StatusBar } from 'react-native';
import { Colors } from 'react-native/Libraries/NewAppScreen';
import { GoogleSignin, GoogleSigninButton, statusCodes } from '@react-native-community/google-signin';
import auth from '@react-native-firebase/auth';
GoogleSignin.configure({ webClientId: '532405863926-94v4mgqg18ajc2g7tk6ttghvsnilooee.apps.googleusercontent.com' });
const App: () => React$Node = () => {
  const [user, setUser] = useState();
  const [authErr, setAuthErr] = useState('');
  useEffect(() => auth().onAuthStateChanged((user) => setUser(user)), []);
  onGoogleSignOut = async () => await auth().signOut()
  getAuthErrorSnip = () => authErr ? <Text>{JSON.stringify(authErr)}</Text> : null
  onGoogleSignIn = async () => {
    try {
      const user = await GoogleSignin.signIn();
      await auth().signInWithCredential(auth.GoogleAuthProvider.credential(user.idToken));
    } catch (error) {
      setAuthErr(error);
    }
  }
  return (
    <SafeAreaView>
      <ScrollView contentInsetAdjustmentBehavior="automatic" style={styles.scrollView}>
        <View style={styles.body}>
          <View style={styles.sectionContainer}>
            <GoogleSigninButton onPress={onGoogleSignIn} ></GoogleSigninButton>
            {getAuthErrorSnip()}
          </View>
        </View>
      </ScrollView>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  scrollView: {
    backgroundColor: Colors.lighter,
  },
  body: {
    backgroundColor: Colors.white,
  },
  sectionContainer: {
    marginTop: 32,
    paddingHorizontal: 24,
  }
});

export default App;

import React,{useffect,useState}来自“React”;
从“react native”导入{SafeAreaView,StyleSheet,ScrollView,View,Text,StatusBar};
从'react native/Libraries/NewAppScreen'导入{Colors};
从'@react native community/google-sign'导入{GoogleSignin,GoogleSignin按钮,statusCodes};
从'@react native firebase/auth'导入身份验证;
配置({webClientId:'532405863926-94v4mgqg18ajc2g7tk6ttghvsnilooee.apps.googleusercontent.com'});
常量应用程序:()=>React$Node=()=>{
const[user,setUser]=useState();
const[authErr,setAuthErr]=useState(“”);
useEffect(()=>auth().onAuthStateChanged((用户)=>setUser(用户)),[]);
onGoogleSignOut=async()=>Wait auth().signOut()
getAuthErrorSnip=()=>authErr?{JSON.stringify(authErr)}:null
onGoogleSignIn=async()=>{
试一试{
const user=wait googlesign.sign();
等待auth().signInWithCredential(auth.GoogleAuthProvider.credential(user.idToken));
}捕获(错误){
setAuthErr(错误);
}
}
返回(
{getAuthErrorSnip()}
);
};
const styles=StyleSheet.create({
滚动视图:{
背景颜色:颜色。颜色较浅,
},
正文:{
背景颜色:Colors.white,
},
节容器:{
玛金托普:32,
水平方向:24,
}
});
导出默认应用程序;
当我运行android并单击登录时看到的内容:

很可能是与客户端id或SHA-1配置相关的错误,请在github上查看与同一错误相关的内容

通过查看您共享的屏幕截图和代码,我认为您使用了错误的客户端id,对于google web client,我认为您应该使用

客户端id
带有
客户端类型:3

而不是

客户端id
带有
客户端类型:1


因此,请尝试在
app.js
文件中修复您的
客户端id
,它应该会起作用。

您选择了错误的SHA1密钥。使用调试变量下的SHA1键,然后重新下载google JSON文件并重建您的应用程序。我没有在ios或android中使用任何firebase sdk进行google登录,这对我来说很好。