简体   繁体   English

Google登录React Native Android登录错误

[英]Google Sign in React Native Android Sign in Error

I am currently using the following module to implement a Google signin: react-native-google-signin . 我目前正在使用以下模块来实现Google登录: react-native-google-signin

I create the button and when pressed am able to select a google account to log in with, however upon selecting an account I get the following error: WRONG SIGNIN Error: DEVELOPER_ERROR at new GoogleSigninError It looks as though a user object is not being created upon signin. 我创建了按钮,当按下该按钮时,便可以选择一个Google帐户登录,但是选择一个帐户时,出现以下错误:WRONG SIGNIN Error:DEVELOPER_ERROR在新的GoogleSigninError上似乎没有创建用户对象登入。 I followed the tutorial pretty thoroughly, is there something I'm not accounting for? 我完全按照本教程进行了学习,有什么我不负责的吗? Relevant code: 相关代码:

constructor(props){
    super(props);

    this.state = {
      user: null,
    }
  }

componentDidMount() {
    this._setupGoogleSignin();
  }

_signIn() {
    GoogleSignin.signIn()
    .then((user) => {
      console.log(user);
      this.setState({user: user});
      this.props.navigator.push({
        component: Account
      });
    })
    .catch((err) => {
      console.log('WRONG SIGNIN', err);
    })
    .done();
  }

async _setupGoogleSignin() {
    try {
      await GoogleSignin.hasPlayServices({ autoResolve: true });
      await GoogleSignin.configure({
        webClientId: 'MY-CLIENT-ID',
        offlineAccess: false
      });

      const user = await GoogleSignin.currentUserAsync();
      console.log(user);
      this.setState({user});
    }
    catch(err) {
      console.log("Play services error", err.code, err.message);
    }
  }

Within render: 在渲染中:

<GoogleSigninButton
    style={{width: 312, height: 48}}
    size={GoogleSigninButton.Size.Wide}
    color={GoogleSigninButton.Color.Light}
    onPress={() => { this._signIn(); }}/>
 componentDidMount() {
    GoogleSignin.configure({
        webClientId: 'YOUR_GOOGLE_CONSOLE_WEB_CLIENT_ID' ,
        forceConsentPrompt: true, // if you want to show the authorization prompt at each login
    });
}
googleSignInHandler = () => {
    GoogleSignin.hasPlayServices()
    .then(res => {
        GoogleSignin.signIn()
        .then(res => {
            console.log(res);
        })
        .catch(err => {
            console.log(err.code);
        });
    })
    .catch(err => {
        console.log(err.message);
    });
}
render() {
    return (
        <View style={styles.container}>
            <GoogleSigninButton
                style={{ width: 48, height: 48 }}
                size={GoogleSigninButton.Size.Icon}
                color={GoogleSigninButton.Color.Dark}
                onPress={this.googleSignInHandler}
            />
        </View>
    );
}

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

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