I am trying to use Facebook Auth for my firebase react native project and I am running into this TypeError at the InitalizeAsync method.
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'],
});
I've been trying to troubleshoot this for the last day or so.
ID_OF_APP is only in the question...not my actual code (for the sake of making this question easier to understand to future viewers).
Try this method
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 })
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.