UJ *_*dia 10 javascript android google-login reactjs react-native
我一直在尝试将社交登录集成到我能够成功登录 facebook 的本机项目中,但无法登录到谷歌。react-native-google-signin库用于谷歌。
我用过的代码。
componentDidMount() {
GoogleSignin.hasPlayServices({ autoResolve: true }).then(() => {
// play services are available. can now configure library
}).catch((err) => {
console.log("Play services error", err.code, err.message);
})
GoogleSignin.configure({
scopes: ["https://www.googleapis.com/auth/drive.readonly"], // what API you want to access on behalf of the user, default is email and profile
// iosClientId: <FROM DEVELOPER CONSOLE>, // only for iOS
webClientId: "xxx", // client ID of type WEB for your server (needed to verify user ID and offline access)
// offlineAccess: true // if you want to access Google API on behalf of the user FROM YOUR SERVER
//hostedDomain: '' // specifies a hosted domain restriction
//forceConsentPrompt: true // [Android] if you want to show the authorization prompt at each login
//accountName: '' // [Android] specifies an account name on the device that should be used
})
.then(() => {
// you can now call currentUserAsync()
});
_signIn = async () => {
try {
await GoogleSignin.hasPlayServices(
)
const userInfo = await GoogleSignin.signIn();
console.log('User Info --> ', userInfo);
this.setState({ userInfo });
} catch (error) {
console.log('Message', error.message);
if (error.code === statusCodes.SIGN_IN_CANCELLED) {
console.log('User Cancelled the Login Flow');
} else if (error.code === statusCodes.IN_PROGRESS) {
console.log('Signing In');
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
console.log('Play Services Not Available or Outdated');
} else {
console.log('Some Other Error Happened');
}
}
};
Run Code Online (Sandbox Code Playgroud)
错误响应:
Message: A non-recoverable sign in failure occurred -catch error
Run Code Online (Sandbox Code Playgroud)
Ash*_*wal 17
我知道,我回答这个问题已经很晚了。我刚刚遇到了同样的问题,花了将近 4-5 个小时来解决这个问题。我找到的解决方案:“当我在 Firebase 上添加支持电子邮件时它开始工作”我认为这不是应用程序或配置问题。这可能是一个应该报告的 firebase 问题,并且在文档中没有任何地方。
关注这里
Apk 链接https://drive.google.com/file/d/1FNFBX-M7PQC6ShCC3KSuOH2E57YGPj6H/view?usp=sharing
go to android folder ./gradlew signingReport Take the SHA1 of Task
:app:signingReport, Variant: debugAndroidTest, Config: debug Update
add fingure print sha1 in your project inside firebae.console.google.com
Run Code Online (Sandbox Code Playgroud)
并在您的项目中再次下载 google-service.json 文件
[错误:发生不可恢复的登录失败]
1. add support email to solve this error
2. and wait 5 minutes your google login will be working fine
Run Code Online (Sandbox Code Playgroud)
gradlew signingReport在 android 文件夹中运行并检查列出的所有sha1,如果您使用的是 firebase,请确保将列表中找到的所有不同sha1添加到 firebase 项目中,然后再次下载 google-services.json 将其替换为旧的在您的项目中再次运行cd android && gradlew clean并构建您的项目
小智 4
这是由于 clientId 造成的。在 google 开发者控制台中,当您为 webClientID 配置项目时,不要创建新项目,而是选择现有项目,即先创建项目,然后选择它来创建凭据。
这对我有用。
并进行登录配置
GoogleSignin.hasPlayServices({ autoResolve: true }).then(() => {
})
.catch((err) => {
console.log("Play services error", err.code, err.message);
})
GoogleSignin.configure({
scopes: ["https://www.googleapis.com/auth/userinfo.profile"],//scopes as you need
webClientId: "***(Your clientId)",
//iosClientId: <FROM DEVELOPER CONSOLE>, // only for iOS
//offlineAccess: true, //(give it true if you need serverAuthCode i.e cross client authorisation)
//hostedDomain: ''
//forceConsentPrompt: true // [Android] if you want to show the authorization prompt at each login
//accountName: ''
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8927 次 |
| 最近记录: |