gpt4 book ai didi

ios - 使用 React-native 的 IOS 版 Google SignIn(博览会)

转载 作者:行者123 更新时间:2023-11-29 05:10:25 24 4
gpt4 key购买 nike

我正在设置一个页面,我可以在其中使用 Google 帐户进行身份验证。这是我的代码:

import React from "react"
import { StyleSheet, Text, View, Image, Button } from "react-native"
import * as Google from "expo-google-app-auth";

export default class App extends React.Component {
constructor(props) {
super(props)
this.state = {
signedIn: false,
name: "",
photoUrl: ""
}
}
signIn = async () => {
try {
const result = await Google.logInAsync({
androidClientId:
"1051966217196.apps.googleusercontent.com",
iosClientId:
"1051966217196.apps.googleusercontent.com",
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
}
})

在 Android 上没问题,一切都很好,但在 IOS 上我遇到了这个错误:

Google 400 - That's an error - Error : redirect_uri_mismatch

哪里出错了?我是原生 react 新手,所以我需要详细的解释。

最佳答案

我在 Google 凭据中将 bundle 标识符更改为 host.exp.exponent 并且它有效。这很奇怪,因为我没有在 app.json 中更改它。但它确实有效。

关于ios - 使用 React-native 的 IOS 版 Google SignIn(博览会),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59735522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com