Reactjs 谷歌登录从被动本机给类型错误-博览会
我正在尝试用谷歌OAuth登录创建一个简单的React原生应用程序。 我已经在google中创建了凭据,并在app.js文件中输入了相同的凭据 该应用程序在android emulator中启动,当我单击“使用谷歌登录”时,它会在控制台中显示错误: “error[TypeError:undefined不是对象(正在评估 “_expo.default.Google”)” 我不知道怎么解决这个问题 这是我的app.jsReactjs 谷歌登录从被动本机给类型错误-博览会,reactjs,react-native,google-oauth,expo,Reactjs,React Native,Google Oauth,Expo,我正在尝试用谷歌OAuth登录创建一个简单的React原生应用程序。 我已经在google中创建了凭据,并在app.js文件中输入了相同的凭据 该应用程序在android emulator中启动,当我单击“使用谷歌登录”时,它会在控制台中显示错误: “error[TypeError:undefined不是对象(正在评估 “_expo.default.Google”)” 我不知道怎么解决这个问题 这是我的app.js import React from "react" import { Style
import React from "react"
import { StyleSheet, Text, View, Image, Button } from "react-native"
import Expo from "expo"
export default class App extends React.Component {
constructor(props) {
super(props)
this.state = {
signedIn: false,
name: "",
photoUrl: ""
}
}
signIn = async () => {
try {
const result = await Expo.Google.logInAsync({
androidClientId:
"**********",
//iosClientId: YOUR_CLIENT_ID_HERE, <-- if you use iOS
scopes: ["profile", "email"]
})
if (result.type === "success") {
this.setState({
signedIn: true,
name: result.user.name,
photoUrl: result.user.photoUrl
})
} else {
console.log("cancelled")
}
} catch (e) {
console.log("error", e)
}
}
render() {
return (
<View style={styles.container}>
{this.state.signedIn ? (
<LoggedInPage name={this.state.name} photoUrl={this.state.photoUrl} />
) : (
<LoginPage signIn={this.signIn} />
)}
</View>
)
}
}
const LoginPage = props => {
return (
<View>
<Text style={styles.header}>Sign In With Google</Text>
<Button title="Sign in with Google" onPress={() => props.signIn()} />
</View>
)
}
const LoggedInPage = props => {
return (
<View style={styles.container}>
<Text style={styles.header}>Welcome:{props.name}</Text>
<Image style={styles.image} source={{ uri: props.photoUrl }} />
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center"
},
header: {
fontSize: 25
},
image: {
marginTop: 15,
width: 150,
height: 150,
borderColor: "rgba(0,0,0,0.2)",
borderWidth: 3,
borderRadius: 150
}
})
从“React”导入React
从“react native”导入{样式表、文本、视图、图像、按钮}
从“世博会”导入世博会
导出默认类App扩展React.Component{
建造师(道具){
超级(道具)
此.state={
签名:错,
姓名:“,
照片网址:“
}
}
signIn=async()=>{
试一试{
const result=wait Expo.Google.logInAsync({
androidClientId:
"**********",
//iosClientId:这里是你的客户ID{
返回(
使用谷歌登录
props.sign()}/>
)
}
const LoggedInPage=props=>{
返回(
欢迎:{props.name}
)
}
const styles=StyleSheet.create({
容器:{
弹性:1,
背景颜色:“fff”,
对齐项目:“中心”,
为内容辩护:“中心”
},
标题:{
尺寸:25
},
图片:{
玛金托普:15,
宽度:150,
身高:150,
边框颜色:“rgba(0,0,0,0.2)”,
边框宽度:3,
边界半径:150
}
})
有什么帮助、建议吗
非常感谢!我通过降级到SDK expo 31.0.0版解决了这个问题。由于expo CLI的最新版本发生了更改,文档中的这个示例不再有效 Google app auth软件包已移动到一个独立软件包-
expo Google app auth
,因此,您需要从该软件包导入Google对象
以下是确保引用正确包的一些步骤
- 确保已安装expo google app auth(您可以使用
)expo install expo google app auth
- 然后您应该使用以下命令导入Google对象:
import*as Google from'expo Google app auth'
- 然后可以使用logInAsync()函数,如下所示:
... const result = await Google.logInAsync({ ... })