React-native google 登录会出现开发人员错误 [英] React-native google signin gives Developer Error

查看:34
本文介绍了React-native google 登录会出现开发人员错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 React-native-google-signin<登录 Google/a> 插件,但它给了我一个 Developer_Error.我所做的与它的文档中提到的完全一样.这是我的代码和步骤.

I am trying Google login using React-native-google-signin plugin but it gives me a Developer_Error.I have done exctly same as mention in its document.here is my code ans steps.

1.使用 npm i react-native-google-signin 安装 react-native-google-signin 插件.2.然后将它与 react-native 链接 react-native-google-signin 联系起来3.之后,我按照文档中提到的那样设置了 build.gradle 文件.

1.Installed react-native-google-signin plugin using npm i react-native-google-signin. 2.Then have linked it with react-native link react-native-google-signin 3.After that i did setup of build.gradle file as they mention it in the documents.

    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.gradle,

4.Updated android/app/build.gradle,

    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.keystore 生成 SHA1 密钥并在 firebase 中生成 google-services.json 文件.

5.Then generate SHA1 key using android studion debug.keystore and generate google-services.json file in firebase.

6.然后像这样设置login.js页面.

6.Then setting up login.js page like this.

    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 是正确的,我已经检查过了.

These are my details so please someone help me on this i cannot find the appropriate solution online.and yes my SHA1 and clientID is correct i have cheked it already.

推荐答案

我也遇到了这个问题,并浏览了许多答案,说检查您的客户 ID 和密钥哈希,我认为这两个都是正确的.

I had this problem too and trawled through many answers saying check your client Id and key hash, both of which I was positive were right.

让它对我有用的是我在项目管理控制台(不是 Firebase)中打开了 OAuth 身份,地址为 https://console.cloud.google.com/apis/credentials 并添加了一个带有正确签名的 Android Oauth 客户端 ID(由于某种原因,我之前没有其中之一).重新下载 GoogleServices json 文件.

The thing that got it working for me was I opened OAuth identities in the project management console (not Firebase) at https://console.cloud.google.com/apis/credentials and added an Android Oauth client Id with the correct signature (I did not have one of these there prior for some reason). Redownload the GoogleServices json file.

我还需要将 webClientId 设置为client_type":3 Oauth 客户端 ID.然后它起作用了.

I also needed to set the webClientId to the "client_type": 3 Oauth client ID. It then worked.

这篇关于React-native google 登录会出现开发人员错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆