简体   繁体   English

在博览会上登录Google Auth无法正常工作

[英]Login google Auth in expo not working properly

when i press the sign in with google button it doesn't do anything 当我按下使用Google按钮登录时,它什么也没做

i followed https://docs.expo.io/versions/latest/sdk/google/ 我遵循了https://docs.expo.io/versions/latest/sdk/google/

the iosClientId: 'my-id', is normally my google clientid but changed it for security reasons iosClientId:“ my-id”,通常是我的Google clientid,但出于安全原因将其更改

import React, { Component } from 'react';
import {StyleSheet, Text, View, Button} from 'react-native';

class LoginScreen extends Component {
    async signInWithGoogleAsync () {
        try {
            const result = await Expo.Google.logInAsync({
                //androidClientId: YOUR_CLIENT_ID_HERE,
                behavior: 'web',
                iosClientId: 'my-id',
                scopes: ['profile', 'email'],
            });

            if (result.type === 'success') {
                return result.accessToken;
            } else {
                return { cancelled: true };
            }
        } catch (e) {
            return { error: true };
        }
    }
    render() {
        return (
            <View style={styles.container}>
                <Button title={"Sign In With Google"}
                 onpress={() =>this.signInWithGoogleAsync()}
                />
            </View>
        );
    }
}
export default LoginScreen;

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF'
    }
});

I expect is when i press the Sign In With Google button it to let me sign in 我希望是当我按下“使用Google登录”按钮时,它可以让我登录

but what im getting is the button not doing anything 但是我得到的是按钮什么都不做

Change your render function to this: 将您的渲染功能更改为此:

render() {
    return (
        <View style={styles.container}>
            <Button title={"Sign In With Google"}
             onPress={() =>this.signInWithGoogleAsync()}
            />
        </View>
    );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM