[英]Error in FB integration with react native
I am trying to integrate FB with my React Native app.我正在尝试将 FB 与我的 React Native 应用程序集成。 I was successfully able to get a login message displayed when I tried the below code for the first time but since then I am getting this message "Facebook Login Error: Alert is not defined".当我第一次尝试以下代码时,我成功地获得了显示的登录消息,但从那时起我收到了这条消息“Facebook 登录错误:警报未定义”。
I took this code from FB developers page and followed the instructions but looks like I am missing something.我从 FB 开发人员页面获取了这段代码并按照说明进行操作,但看起来我遗漏了一些东西。
I'll Appreciate any pointers我会很感激任何指示
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);
Try to import the Alert from the react-native:尝试从 react-native 导入警报:
import {
Text,
View,
Alert
} from 'react-native';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.