Google SignIn для IOS с React-native (выставка) - PullRequest
0 голосов
/ 14 января 2020

Я настраиваю страницу, где я могу идентифицировать с учетной записью 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 - Это ошибка - Ошибка: redirect_uri_mismatch

Можете ли вы помочь мне понять, в чем дело? Я новичок, чтобы реагировать на родную, поэтому мне нужны подробные объяснения. Спасибо за ваше время и помощь.

1 Ответ

0 голосов
/ 15 января 2020

Я изменил идентификатор пакета на host.exp.exponent в учетных данных Google, и он работает. Это странно, потому что я не изменил его в приложении. json. Но это работает. Может быть, это могло бы помочь другим.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...