我正在我的React Native应用程序中实现Firebase社交登录,这个问题已经被问过很多次了,我已经遵循了其他问题中的所有内容,但根本不起作用,这就是我所做的:
cd/android && ./gradlew signingReport
从我的项目基于此文档生成证书指纹并复制以下变体信息的 SHA1:
Variant: debug Config: debug Store: C:\Users\USER-NAME\PROJECT-NAME\android\app\debug.keystore
然后将其粘贴到我注册的 Android 应用程序下的 firebase 中。
4.我检查了json文件中的
oauth_client/client_id
,它与谷歌控制台中自动生成的OAuth 2.0 Client IDs
相同
我已在 firebase 公共项目信息中添加了支持电子邮件。
Firebase 所需的所有预设置均已完成基于此文档
在firebase中创建新应用程序时的包名称与
AndroidManifest.xml
中的名称相同
在 Google 开发者控制台的 OAuth 中,应用程序名称与
AndroidManifest.xml
中的名称相同
我已经重建了几次应用程序,但仍然出现错误。
我的代码如下所示:
googleLogin: async () => {
try {
GoogleSignin.configure({
webClientId: "542246894154-fgfa3e4b3maonkftkvkd1lvrueda7iop.apps.googleusercontent.com",
offlineAccess: true
});
const data = await GoogleSignin.signIn();
const credential = firebase.auth.GoogleAuthProvider.credential(data.idToken, data.accessToken);
const firebaseUserCredential = await auth().signInWithCredential(credential);
if (firebaseUserCredential) setLoggedInGoogle(true);
if (typeof success === 'function') success();
} catch (error) {
if (error.code === statusCodes.SIGN_IN_CANCELLED) {
// when user cancels sign in process,
Alert.alert('Process Cancelled')
} else if (error.code === statusCodes.IN_PROGRESS) {
// when in progress already
Alert.alert('Process in progress')
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
// when play services not available
Alert.alert('Play services are not available')
} else {
// some other error
Alert.alert('Something else went wrong... ', error.toString())
setError(error)
}
}
}
我将非常感谢任何帮助,因为我在这将近 4 个小时中遇到了同样的错误。
keytool -list -v -keystore /Volumes/Development/Sample/Authentication/android/app/debug.keystore -alias androiddebugkey -storepass android -keypass android (粗体请包含debug.keystore路径)
复制 SHA-1 密钥并粘贴到 android 的 firebase 指纹中
从 Google 开发者控制台检查 Web 客户端 ID。它在 firebase 和代码中应该是相同的
GoogleSignin.configure({ 网络客户端ID: '', });
完成后,下载一个新的googleService.json文件并粘贴android->app
终于有功能了
const OnGoogleSignin = async () => { 尝试 { const {idToken} = 等待 GoogleSignin.signIn();
// Create a Google credential with the token
const googleCredential = Auth.GoogleAuthProvider.credential(idToken);
// Sign-in the user with the credential
await Auth().signInWithCredential(googleCredential);
} catch (e) {
console.log('googleLoginError', e);
}
};