gpt4 book ai didi

firebase - Google 在 React Native 中使用 Firebase 登录

转载 作者:行者123 更新时间:2023-12-03 00:42:45 27 4
gpt4 key购买 nike

我尝试使用 Google 登录,但出现以下错误:

code: "auth/operation-not-supported-in-this-environment" message: "This operation is not supported in the environment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled."

这是代码:

const provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
firebase.auth().signInWithPopup(provider)
.then((result) => {
console.log(result);
})
.catch((error) => {
console.log(error);
})

其他信息:

  • “firebase”:“^3.7.1”
  • "react-native": "^0.42.0"
  • 平台:Android

有什么想法吗?提前致谢!

最佳答案

首先我使用react-native-google-signin使用 Google 登录。关注这些steps配置它。

确保您正确 sign您的 APK(调试或发布)。

app/build.gradle 中,从使用它的依赖项中排除 com.google.android.gms,如下所示:

compile(project(":react-native-google-signin")){
exclude group: "com.google.android.gms" // very important
}

然后将您的 Google token 与 Firebase 关联:

const provider = firebase.auth.GoogleAuthProvider;
const credential = provider.credential(token);
firebase.auth().signInWithCredential(credential)
.then((data) => {
console.log('SUCCESS', data);
})
.catch((error) => {
console.log('ERROR', error);
});

我使用的是 firebase 3.7.1

这是我的依赖项在 app/build.gradle

中的样子
dependencies {
compile project(':react-native-facebook-login')
compile (project(':react-native-fcm')){
exclude group: "com.google.firebase"
}
compile project(':react-native-vector-icons')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+"
compile(project(":react-native-google-signin")){
exclude group: "com.google.android.gms" // very important
}
compile ('com.google.firebase:firebase-core:10.0.1') {
force = true;
}
compile ('com.google.firebase:firebase-messaging:10.0.1') {
force = true;
}
compile ('com.google.android.gms:play-services-auth:10.0.1') {
force = true;
}
}

关于firebase - Google 在 React Native 中使用 Firebase 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42792279/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com