typescript - TypeError:未定义不是对象(评估'_ExponentFacebook.default.initializeAsync')
问题描述
我正在尝试将 Facebook Auth 用于我的 firebase react native 项目,并且在 InitalizeAsync 方法中遇到了这个 TypeError。
import * as Facebook from 'expo-facebook';
export const loginWithFacebook = async () => {
await Facebook.initializeAsync('ID_OF_APP');
const {type, token}: any = await Facebook.logInWithReadPermissionsAsync({
permissions: ['public_profile', 'email'],
});
在过去的一天左右,我一直在尝试解决这个问题。
ID_OF_APP 仅在问题中......不是我的实际代码(为了让未来的观众更容易理解这个问题)。
解决方案
试试这个方法
import { AccessToken, LoginManager } from "react-native-fbsdk"
state = {
email: '',
sso_token: '',
sso_uid: '',
loading: false,
}
initUser(token) {
axios({
method: 'GET',
url: `https://graph.facebook.com/v2.5/me?fields=email,name,friends&access_token=${token}`,
responseType: 'json'
}).then((response) => {
const { data } = response
const { first_name, last_name } = this.split_name(data.name)
this.setState(
{ sso_token: token, sso_uid: data.id, email: data.email, first_name, last_name },
)
}).catch((err) => { console.warn(err) })
}
onFBSignin() {
this.setState({ loading: true })
LoginManager.logInWithPermissions(["email", "public_profile"])
.then(result => {
if (result.isCancelled) {
this.setState({ loading: false })
}
else {
AccessToken.getCurrentAccessToken()
.then((data) => {
const { accessToken } = data
this.initUser(accessToken)
})
.catch((error) => {
console.warn(error)
})
}
})
.catch(error => {
console.warn(error)
this.setState({ loading: false })
}
推荐阅读
- unity3d - 如何在 Unity3D 中切片 2D 游戏对象?
- excel - VBA cell.value 作为字符串 - 类型不匹配
- python - 通过 systemd 服务启动烧瓶
- python-3.x - Pandas:在 str.contain 方法中隔离非常具体的数据
- css - 使用角度弹性布局动态添加网格框
- json - 为什么我的 Velocity 模板语言条件不起作用?
- jquery - Devexterme 数据网格中的 editCellTemplate 问题
- c - Ubuntu 不会编译 C 文件,错误“
: 没有这样的文件或目录” - php - 使用带有常量数据的变量密钥与使用带有变量数据的常量密钥一样安全,后者在 PHP 中使用 hash_hmac() 对 uri 进行签名
- ios - iOS CIFilter RAW 图像内存问题(Objective-C)