![](/img/trans.png)
[英]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.