我需要在我的 React native 应用程序中使用 google 登录。所以我在谷歌上搜索了很多,我发现 react-native-google-signin这看起来很棒,但我遇到了一个错误。
我遵循 READ.me 中的所有步骤和 Androide Guide
我有以下代码:
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>
);
当我点击登录按钮时,会弹出一个窗口供我选择要使用的谷歌帐户。但是当我选择帐户时,出现以下错误:错误登录错误:未知状态代码:12501(…)
所以我查看了 Androide Guide 底部的常见问题解答
并确认我在 android/app/google-services.json
中的 certificate_hash 是相同的。
我还检查了我的 app/build.graddle
中的应用程序 ID 是否与我在谷歌云中输入的相同。
我认为问题出在我在我的范围内传递的 WebclientId,我传递的是 web 类型 1,但已经尝试了 oauth 2 中的两个客户端 id
我在 githubs issues 中搜索,发现有人告诉我要再次下载 google-services。我这样做了,但文件与我之前下载的文件相同。 很确定,我错过了一些东西,但不要什么。 谁能帮帮我?
我在 github 中打开了一个问题,但我没有得到太多的行动。
提前致谢
最佳答案
您分享的自述文件状态
D. After the sign-in completes I get the following error error code 12501. what to do ?
This is a permission error. Make sure the certificate_hash in android/app/google-services.json matches your certificate.
To get your sha1-hash
keytool -exportcert -keystore ~/.android/debug.keystore -list -v Also make sure the application id matches the one you enter on the cloud console.
有一个 .user 文件(或类似的文件)我想不起来了。它位于隐藏文件夹中,因此您必须使用查找器查找该文件并将其删除。它应该工作。查看您的代码用于查找它的所有路径,您将必须为路径调试这些文件。
关于javascript - react native 谷歌登录返回状态代码 : 12501,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38542531/