为什么我会收到 com.google.android.gms.common.api.ApiException: 10

问题描述 投票:0回答:1

我知道这个问题一直在到处问,但我无法弄清楚..

以下这些事情我已经做过十多次了。

  1. 从google获取正确的webClientId
  2. 从 gradle 获取 sha1 并将其添加到 firebase
  3. 更新了我的 google-services.json

我的代码:

import {GoogleSignin} from '@react-native-google-signin/google-signin';

GoogleSignin.configure({
  webClientId: 'my_id (I didn't want to include the real id)',
});

const signInWithGoogle = async () => {
    try {
        // Attempt to sign in with Google
        const { idToken } = await GoogleSignin.signIn();

        // Create a Google credential with the token
        const googleCredential = auth.GoogleAuthProvider.credential(idToken);

        // Sign-in the user with the credential
        const userCredential = await auth().signInWithCredential(googleCredential);

        console.log('Signed in with Google!', userCredential.user);

        // Proceed with your app logic here (e.g., navigation, storing user data)
    } catch (error) {
        // Log detailed error information
        console.error("Google Sign-In error", error);
        console.log(`Error code: ${error.code}`);
        console.log(`Error message: ${error.message}`);
        console.log(`Full error: ${JSON.stringify(error, null, 2)}`);

        // Display a more detailed error message
        Alert.alert('Google Sign-In Error', `Failed to sign in with Google: ${error.message}`);
    }
};
android react-native
1个回答
0
投票

我发现您需要确保生成正确的 SHA 密钥。 去: android->app->build.gradle:查找“signingConfigs”,您想要生成 SHA 密钥的文件位于“storeFile 文件”之后。例如我的是“storeFile file('debug.keystore')。您需要记下所有 4 个配置选项。

因此:

cd android/app

然后:

keytool -list -v -keystore <your.keystore> -alias <yourkeyalias> -storepass <yourstorepass> -keypass <yourkeypass>

© www.soinside.com 2019 - 2024. All rights reserved.