反应原生谷歌登录没有登录

时间:2021-02-04 13:58:33

标签: react-native

import React, { useEffect, useState } from 'react';
import {
    GoogleSignin,
    GoogleSigninButton,
    statusCodes,
} from '@react-native-community/google-signin';
import { Text } from 'react-native';

function GoogleSignIn() {
    const [userInfo, setUserInfo] = useState([])
    const [load, setLoad] = useState(false)
    const signIn = async () => {
        try {
            await GoogleSignin.hasPlayServices();
            const userInfo = await GoogleSignin.signIn();
            setUserInfo(userInfo);
            setLoad(!load)
            console.log(userInfo)
        } catch (error) {
            if (error.code === statusCodes.SIGN_IN_CANCELLED) {
                console.log('user cancelled the login flow')
            } else if (error.code === statusCodes.IN_PROGRESS) {
                console.log('// operation (e.g. sign in) is in progress already')
            } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
                console.log(' // play services not available or outdated')
            } else {
                console.log('something maybe wrong with SHA1 key')
            }
        }
    };
    const signOut = async () => {
        try {
            await GoogleSignin.revokeAccess();
            await GoogleSignin.signOut();
            setUserInfo(userInfo = Null); // Remember to remove the user from your app's state as well
            setLoad(false)
        } catch (error) {
            console.error(error);
        }
    };
    useEffect(() => {
        GoogleSignin.configure({
            webClientId: '476307937622-13qdp25mgqe7t4n3uqbfrqsmgs6us3n4.apps.googleusercontent.com', // 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 SERVE
        });
    })
    return (
        <>
            <GoogleSigninButton
                style={{ width: 192, height: 48 }}
                size={GoogleSigninButton.Size.Wide}
                color={GoogleSigninButton.Color.Dark}
                onPress={signIn}
            />
            {load ? <Text> success
            </Text>: <Text> failed</Text>}
        </>
    );
}
export default GoogleSignIn

这是谷歌登录组件,我无法弄清楚该代码有什么问题,它没有登录,所以我检查了我的调试器,它打印出这个“SHA1可能有问题”,因为我设置了它运行 ./gradlew signingReport 后要使用的 SHA1 我得到了三个 Task :app:signingReportTask :react-native-community_google-signin:signingReport ,Task :react-native-firebase_admob:signingReportTask :react-native-firebase_auth:signingReport 并且根据谷歌我们必须使用

    > Task :app:signingReport
Variant: debug
Config: debug
Store: ~/.android/debug.keystore
Alias: AndroidDebugKey
MD5: A5:88:41:04:8D:06:71:6D:FE:33:76:87:AC:AD:19:23
SHA1: A7:89:E5:05:C8:17:A1:22:EA:90:6E:A6:EA:A3:D4:8B:3A:30:AB:18
SHA-256: 05:A2:2C:35:EE:F2:51:23:72:4D:72:67:A5:6C:8C:58:22:2A:00:D6:DB:F6:45:D5:C1:82:D2:80:A4:69:A8:FE
Valid until: Wednesday, August 10, 2044

variant 但我在 Task :react-native-community_google-signin:signingReport 中找不到任何这样的变体,它只包含这两个变体

> Task :react-native-community_google-signin:signingReport
Variant: releaseUnitTest
Config: none
----------
Variant: debugUnitTest
Config: debug
Store: /home/placeholer/.android/debug.keystore
Alias: AndroidDebugKey
MD5: some value
SHA1: some value
SHA-256: some value
Valid until: Sunday, January 1, 2051
----------

Variant: debugAndroidTest
Config: debug
Store: /home/placeholder/.android/debug.keystore
Alias: AndroidDebugKey
MD5: some value
SHA1: some value
SHA-256:some value
Valid until: Sunday, January 1, 2051
----------

要使用哪个 SHA1 密钥?还有其他问题吗?

0 个答案:

没有答案