我正在尝试使用Facebook验证用户身份。我能够成功地请求许可并在facebook平台上授权用户,但是随后该应用返回并在重定向时出错,并产生以下错误-> Facebook Login Error: Can't find variable: Alert
。是的,我的Facebook登录方法中使用Alert
语法,但是我根本无法找到触发此错误的位置。
有人曾经历过吗?
facebookSignIn = async () => {
try {
const {
type,
token,
expires,
permissions,
declinedPermissions,
} = await Expo.Facebook.logInWithReadPermissionsAsync('<APP ID>', {
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}!`);
this.props.navigation.navigate('SenderHPP');
} else {
// type === 'cancel'
}
} catch ({ message }) {
alert(`Facebook Login Error: ${message}`);
}
};
答案 0 :(得分:0)
请尝试将此行添加到顶部。
import { Alert } from 'react-native';
答案 1 :(得分:0)
您是从react-native导入Alert吗?
首先
import { Alert } from 'react-native';
你很好!
答案 2 :(得分:0)
您应该添加
import *
作为Facebook,来自“ expo-facebook”;
答案 3 :(得分:0)
Alert.alert抛出此错误。将其替换为“ console.log”或简单警报。