我目前正在使用以下模块实施Google登录:https://github.com/devfd/react-native-google-signin
我创建了按钮,当按下时我可以选择要登录的Google帐户,但是在选择帐户时我收到以下错误:错误的SIGNIN错误:在新的GoogleSigninError上的DEVELOPER_ERROR 看起来好像在登录时没有创建用户对象。我非常彻底地遵循了教程,有什么我不考虑的吗? 相关代码:
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);
}
}
在渲染中:
<GoogleSigninButton
style={{width: 312, height: 48}}
size={GoogleSigninButton.Size.Wide}
color={GoogleSigninButton.Color.Light}
onPress={() => { this._signIn(); }}/>
答案 0 :(得分:0)
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>
);
}