我正在try 使用React-native-google-signin插件登录谷歌,但它给了我一个开发者错误.我所做的和文件中提到的完全一样.这是我的代码和步骤.

1.使用npm i react native google signin安装react native google signin插件.

    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
        googlePlayServicesAuthVersion = "15.0.1"
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2' 
        classpath 'com.google.gms:google-services:3.2.1' 
    }
    allprojects {
        repositories {
                mavenLocal()
                google() 
                maven {url "https://maven.google.com"}
                jcenter()
                maven {
                // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
                url "$rootDir/../node_modules/react-native/android"
                }
                maven {
                    url 'https://maven.google.com/'
                    name 'Google'
                }
        }
    }

4.更新了android/app/build.格雷德尔,

    dependencies {

        implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
        implementation project(':react-native-fbsdk')
        compile project(':react-native-vector-icons')
        compile project(':react-native-fused-location')
        compile project(':react-native-fs')
        compile project(':react-native-image-resizer')
        compile project(':react-native-geocoder')
        compile project(':react-native-device-info')
        compile project(':react-native-image-picker')
        compile fileTree(dir: "libs", include: ["*.jar"])
        compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
        compile "com.facebook.react:react-native:+"  // From node_modules
        implementation project(":react-native-google-signin")
        compile (project(':react-native-maps')){
            exclude group: "com.google.android.gms" 
        }
        implementation 'com.google.android.gms:play-services-auth:15.0.1'
        implementation 'com.google.android.gms:play-services-maps:15.0.1'
        implementation 'com.google.android.gms:play-services-location:15.0.1'
        implementation 'com.google.android.gms:play-services-base:15.0.1' 

    }

    task copyDownloadableDepsToLibs(type: Copy) {
        from configurations.compile
        into 'libs'
    }
    apply plugin: 'com.google.gms.google-services' 

5.然后使用android studion debug生成SHA1密钥.密钥库和生成谷歌服务.firebase中的json文件.

6.然后设置登录.像这样的页面.

    async componentDidMount() {
        this._configureGoogleSignIn();

    }
    _configureGoogleSignIn() {
        GoogleSignin.configure({
            webClientId: '775060548127-5nfj43q15l75va9pfav2jettkha7hm2a.apps.googleusercontent.com',// my clientID
            offlineAccess: false
        });
    }
    async GoogleSignin() {
    try {
        await GoogleSignin.hasPlayServices();
        const userInfo = await GoogleSignin.signIn();
        // this.setState({ userInfo, error: null });
        Alert.alert("success:" + JSON.stringify(userInfo));

    } catch (error) {
        if (error.code === statusCodes.SIGN_IN_CANCELLED) {
            // sign in was cancelled
            Alert.alert('cancelled');
        } else if (error.code === statusCodes.IN_PROGRESS) {
            // operation in progress already
            Alert.alert('in progress');
        } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
            Alert.alert('play services not available or outdated');
        } else {
            Alert.alert('Something went wrong', error.toString());
            this.setState({
                error,
            });
        }
    }
}

这些是我的详细信息,所以请有人帮助我,我无法在网上找到合适的解决方案.是的,我的SHA1和clientID是正确的,我已经判断过了.

推荐答案

我也遇到了这个问题,我仔细研究了很多答案,比如判断你的客户Id和密钥哈希,我认为这两个答案都是正确的.

让它对我起作用的是,我在项目管理控制台(而不是Firebase)中以https://console.cloud.google.com/apis/credentials打开了OAuth标识,并添加了一个具有正确签名的Android OAuth客户端Id(因为某种原因,我之前没有其中一个).重新下载谷歌服务json文件.

我还需要将webClientId设置为"client_type":3 Oauth client ID.然后它就工作了.

React-native相关问答推荐

在原生react 中更改图像源URI时闪烁

React Native 应用程序没有在之前的工作代码中执行任何操作就无法运行

你使用 react native 应该学习 react.js 吗?

如果没有启用远程调试器,React Native 代码将无法工作

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

滚动到具有可变元素大小的 FlatList 中的某些索引的有效方法

React Native 上传到 S3 存储空间

使用 React Navigation 制作离开屏幕的动画

Typescript:onPress 类型

如何在 React 中使用带有钩子的生命周期方法?

在 react-native 中设置动态 'initialRouteName'

如何将props传递给 React Navigation 导航器中的组件?

iOS ActionSheet 的 Android 类似功能

居中图像 React Native 加载屏幕

React Native Build Error on IOS - typedef 用不同类型重新定义('uint8_t'(又名'unsigned char')与'enum clockid_t')

为react-native TextInput 设置边框

com.facebook.react.bridge.readablenativemap 不能转换为 java.lang.string

使用 React Native 运行 Firebase 3.0 时出错

Gradlew bundleRelease 不会在 react-native 中生成发布 apk

在 React Native 中向组件传递参数