我正在尝试对我的Firebase React本机项目使用Facebook Auth,并且在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仅在问题中……而不是我的实际代码(为了使以后的读者更容易理解此问题)。
答案 0 :(得分:0)
尝试此方法
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 })
}