本文介绍了React-native Google身份验证Android DEVELOPER_ERROR代码10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

react-native init testAuthGoogle && cd testAuthGoogle && (cd android; ./gradlew signingReport) to create a new project and show the SHA1

> Task :app:signingReport
Variant: debugAndroidTest
Config: debug
Store: /Users/anand/ws/rn01/testAuthGoogle/android/app/debug.keystore
Alias: 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
Valid until: Tuesday, April 30, 2052

将SHA1复制到firebase中并创建了android应用

Copied the SHA1 into firebase and created the android app

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

android/build.gradle中:

  • 添加的依赖项:classpath("com.google.gms:google-services:4.3.3")

android/app/build.gradle中:

  • 应用插件:apply plugin: "com.google.gms.google-services"
  • 添加了依赖项implementation 'com.google.firebase:firebase-analytics:17.5.0'implementation 'com.google.firebase:firebase-auth:19.4.0'
  • Apply plugin: apply plugin: "com.google.gms.google-services"
  • Added dependencies implementation 'com.google.firebase:firebase-analytics:17.5.0' and implementation 'com.google.firebase:firebase-auth:19.4.0'

安装了其他依赖项:

npm install --save @react-native-firebase/app @react-native-firebase/auth @react-native-community/google-signin

google-services.json文件复制client_id,以在app.js中使用它.

Copied the client_id from google-services.json file to use it in 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;

当我做react-native run-android并单击Sign in时,我看到的是:

What I see when i did react-native run-android and click on Sign in:

推荐答案

最有可能是与您的client_id或SHA-1配置有关的错误,请查看此问题与同一错误相关.

Most likely it is an error related to your client_id or SHA-1 configuration, check out this issue on github related to the same error.

通过查看您分享的屏幕截图和代码,我认为您使用的是错误的client_id,对于 google网络客户端,我相信您应该使用

By looking at the screenshots and code you have shared, it looks to me you are using wrong client_id, for google web client, I believe you should be using

client_idclient_type : 3

代替

client_idclient_type : 1

所以请尝试在app.js文件中修复您的client_id,它应该可以工作.

so try fixing your client_id in app.js file and it should work.

这篇关于React-native Google身份验证Android DEVELOPER_ERROR代码10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:22