Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript react本机google登录返回状态代码:12501_Javascript_React Native_Google Play Services_Google Signin - Fatal编程技术网

Javascript react本机google登录返回状态代码:12501

Javascript react本机google登录返回状态代码:12501,javascript,react-native,google-play-services,google-signin,Javascript,React Native,Google Play Services,Google Signin,我需要谷歌登录我的react原生应用程序。所以我用谷歌搜索了很多次,我发现这看起来很棒,但我有一个错误 我遵循和中的所有步骤 我有以下代码: componentDidMount() { GoogleSignin.hasPlayServices({autoResolve: true}).then(() => { // play services are available. can now configure library GoogleSig

我需要谷歌登录我的react原生应用程序。所以我用谷歌搜索了很多次,我发现这看起来很棒,但我有一个错误

我遵循和中的所有步骤

我有以下代码:

 componentDidMount() {


     GoogleSignin.hasPlayServices({autoResolve: true}).then(() => {
        // play services are available. can now configure library
        GoogleSignin.configure({
            scopes: [
                'email', 'profile', 'https://www.googleapis.com/auth/plus.profile.emails.read', 'https://www.googleapis.com/auth/plus.login'
            ],
            webClientId: 'web-clientid from the console developper',
            offlineAccess: true
        }).then(() => {
            // you can now call currentUserAsync()
            GoogleSignin.currentUserAsync().then((user) => {
                console.log('USER', user);
            }).done();
        });
     });
}

signIn() {
    GoogleSignin.signIn()
        .then((user) => {
            console.log(user);
        })
        .catch((err) => {
            console.log('WRONG SIGNIN', err);
        })
        .done();
}

 render() {
    return (
        <Image source={BACKGROUND} style={styles.container}>
            <Image source={ICON}></Image>
            <Text style={styles.welcome}>
                APP TEST
            </Text>

            <GoogleSigninButton
                style={{width: 230, height: 48}}
                size={GoogleSigninButton.Size.Standard}
                color={GoogleSigninButton.Color.Light}
                onPress={this.signIn}
            />
        </Image>
    );
componentDidMount(){
hasPlayServices({autoResolve:true})。然后(()=>{
//播放服务可用。现在可以配置库
谷歌签名({
范围:[
'电子邮件','个人资料','https://www.googleapis.com/auth/plus.profile.emails.read', 'https://www.googleapis.com/auth/plus.login'
],
webClientId:“来自控制台开发程序的web客户端ID”,
offlineAccess:正确
}).然后(()=>{
//现在可以调用currentUserAsync()
GoogleSignin.currentUserAsync()。然后((用户)=>{
console.log('USER',USER);
}).完成();
});
});
}
签名(){
谷歌签名
。然后((用户)=>{
console.log(用户);
})
.catch((错误)=>{
console.log('错误登录',错误);
})
.完成();
}
render(){
返回(
应用程序测试
);
当我点击“登录”按钮时,会弹出一个窗口,供我选择要使用的google帐户。但当我选择该帐户时,我出现以下错误:错误登录错误:未知状态代码:12501(…)

因此,我查看了本书底部的常见问题解答 并确认我在
android/app/google services.json
中的证书哈希相同。 我还检查我的
app/build.graddle
中的应用程序id是否与我在谷歌云中输入的相同

我认为问题在于我在我的作用域中传递的WebclientId,我在web类型1中传递,但是已经尝试了oauth 2中的两个客户端id

我在githubs中搜索,发现有人告诉我再次下载google服务。我这样做了,但该文件与我以前下载的文件相同。 很确定,我错过了一些东西,但别忘了什么。 有人能帮我吗

我在github中打开了一个问题,但我没有得到多少行动


提前感谢您共享的自述文件

D.登录完成后,我得到以下错误代码 怎么办

这是权限错误。请确保证书\u散列在 android/app/google-services.json与您的证书匹配

为了得到你的sha1哈希

keytool-exportcert-keystore~/.android/debug.keystore-list-v 确保应用程序id与您在云中输入的id匹配 控制台


有一个.user文件(或类似文件)我记不得了。它在一个隐藏的文件夹中,因此您必须使用finder查找并删除该文件。然后它应该可以工作。查看代码用于查找该文件的所有路径,您必须调试这些文件的路径。

这可能会对您有所帮助,请尝试以下操作:

  • 检查您的google-services.json证书\u哈希代码。 将其与您的Android签名证书SHA-1匹配。 使用此链接可以访问他们的
  • 我已经在emulator上测试了它,但emulator没有google play服务,所以我在我的android手机上测试了它
  • 使用休闲代码

    import {GoogleSignin, GoogleSigninButton} from 'react-native-google-signin';
    
然后

componentDidMount(){
谷歌签名({
范围:[
'电子邮件','个人资料','https://www.googleapis.com/auth/plus.profile.emails.read', 'https://www.googleapis.com/auth/plus.login'
],
webClientId:“在此处使用oauth_客户端[{client_id}]”,//参考以下示例:
offlineAccess:正确
}).然后(()=>{
//现在可以调用currentUserAsync()
GoogleSignin.currentUserAsync()。然后((用户)=>{
//user=GoogleSignin.currentUser();
console.log('USER',USER);
this.setState({user:user});
}).完成();
});
}
_签名(){
谷歌签名
。然后((用户)=>{
log('this1'+JSON.stringify(用户));
})
.catch((错误)=>{
console.log('错误登录',错误);
})
.完成();
}
_签出(){
GoogleSignin.signOut()
.然后(()=>{
console.log('out');
})
.catch((错误)=>{
});
}
render(){
返回(
欢迎来到这里!
要开始,请编辑index.android.js
双击键盘上的R以重新加载,{'\n'}
摇动或按下开发菜单的菜单按钮
签到
);
}
:示例-->WebClient:'1059……….googleusercontent.com'是google-services.json oauth_client[]中的两个客户端Id使用第一个。您可以将其与下面给出的凭据链接进行比较…名称:Web客户端类型:Web应用程序客户端Id:1059…….googleusercontent.com

这解决了我的问题。 祝你有美好的一天。
谢谢。:)

即使我传真了这个问题,我还是通过以下步骤解决了它

  • 创建密钥存储并使用SHA-1证书指纹
  • 在以下位置创建OAuth客户端Id:
  • 选择应用程序类型android,输入包名,输入在步骤1创建的SHA-1证书指纹
  • 对调试和产品SHA-1证书指纹重复上述步骤

    注意:我们需要按照上述步骤为应用程序签名后生成的SHA-1再创建一个OAuth客户端Id

    注意:我们尚未完成,请使用客户端id再创建一个web应用程序OA,并使用web应用程序客户端id
    componentDidMount() {
        GoogleSignin.configure({
            scopes: [
                'email', 'profile', 'https://www.googleapis.com/auth/plus.profile.emails.read', 'https://www.googleapis.com/auth/plus.login'
            ],
            webClientId: 'use here oauth_client[{client_id}]',//refer this given below example:
            offlineAccess: true
        }).then(() => {
            // you can now call currentUserAsync()
            GoogleSignin.currentUserAsync().then((user) => {
                 //user = GoogleSignin.currentUser();
                console.log('USER', user);
                this.setState({user: user});
            }).done();
        });
    }
    
    _signIn() {
        GoogleSignin.signIn()
            .then((user) => {
                console.log('this1' + JSON.stringify(user));                
            })
            .catch((err) => {
                console.log('WRONG SIGNIN', err);
            })
            .done();
    }
    
    _signOut(){
        GoogleSignin.signOut()
            .then(() => {
                console.log('out');
            })
            .catch((err) => {
    
            });
    }
    
    render() {
    
        return (
            <View style={styles.container}>
                <Text style={styles.welcome}>
                    Welcome to React Native!
                </Text>
                <Text style={styles.instructions}>
                    To get started, edit index.android.js
                </Text>
                <Text style={styles.instructions}>
                    Double tap R on your keyboard to reload,{'\n'}
                    Shake or press menu button for dev menu
                </Text>
                <GoogleSigninButton
                    style={{width: 48, height: 48}}
                    size={GoogleSigninButton.Size.Icon}
                    color={GoogleSigninButton.Color.Dark}
                    onPress={this._signIn.bind(this)}/>
                <TouchableHighlight>
                    <Text onPress={this._signOut.bind(this)}>
                        signout
                    </Text>
                </TouchableHighlight>
            </View>
        );
    }