[英]TypeError: undefined is not an object (evaluating 'this._callListeners.bind')
[英]TypeError: undefined is not an object (evaluating '_ExponentFacebook.default.initializeAsync')
我正在尝试将 Facebook Auth 用于我的 firebase 反应本机项目,我在 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 })
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.