【问题标题】:Error in FB integration with react nativeFB 与 react native 集成时出错
【发布时间】:2020-11-15 16:31:12
【问题描述】:

我正在尝试将 FB 与我的 React Native 应用程序集成。当我第一次尝试以下代码时,我成功地显示了一条登录消息,但从那以后我收到了这条消息“Facebook 登录错误:未定义警报”。

我从 FB 开发人员页面获取此代码并按照说明进行操作,但看起来我遗漏了一些东西。

我会感谢任何指针

import React from 'react';
import styles from '../styles'
import {connect} from 'react-redux';
import {login} from '../redux/actions'
import * as Facebook from 'expo-facebook';

import { 
  Text, 
  View
} from 'react-native';

class Home extends React.Component {
  state = {}

  componentWillMount() {
    this.props.dispatch(login("Whats Upp"))
    this.login()
  }

  login = async () => {
    try {
      await Facebook.initializeAsync({
        appId: '1742056282625463',
      });
      const {
        type,
        token,
        expirationDate,
        permissions,
        declinedPermissions,
      } = await Facebook.logInWithReadPermissionsAsync({
        permissions: ['public_profile'],
      });
      if (type === 'success') {
        // Get the user's name using Facebook's Graph API
        const response = await fetch(`https://graph.facebook.com/me?access_token=${token}`);
        Alert.alert('Logged in!', `Hi ${(await response.json()).name}!`);
      } else {
        // type === 'cancel'
      }
    } catch ({ message }) {
      alert(`Facebook Login Error: ${message}`);
    }
  }


  render() {
    return (
      <View>
        <Text>{this.props.user}</Text>
      </View>
    )
  }
}

function mapStateToProps(state) {
  return {
    user: state.user
  };
}
export default connect(mapStateToProps)(Home);

【问题讨论】:

    标签: reactjs react-native facebook


    【解决方案1】:

    尝试从 react-native 导入 Alert:

    import { 
      Text, 
      View,
      Alert
    } from 'react-native';
    

    【讨论】:

      猜你喜欢
      • 2015-06-05
      • 2020-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      • 2021-09-18
      • 1970-01-01
      相关资源
      最近更新 更多