<LoginButton
publishPermissions={["email", "user_friends", "user_photos"]}
....
import { LoginButton, AccessToken, LoginManager } from 'react-native-fbsdk';
<LoginButton
readPermissions={["email", "public_profile"]}
onLoginFinished={
(error, result) => {
if (error) {
console.log("login has error: " + result.error);
} else if (result.isCancelled) {
console.log("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
async (data) => {
const FBtoken = data.accessToken.toString();
await saveStorage('FBtoken', FBtoken);
const userFbInfo = await get(`https://graph.facebook.com/me?access_token=${FBtoken}&fields=id,name,picture,email,friendlists,birthday`);
await saveStorage('userFbInfo', JSON.stringify(
userFbInfo
));
context.props.goMainPage();
}
)
}
}
}
onLogoutFinished={() => this.logoutFinish()}
/>
<Button
title="Continute with FB"
onPress={() => this.FBLoginTrigger()}
/>
FBLoginTrigger() {
const context = this;
LoginManager.logInWithReadPermissions(["email", "public_profile"]).then(
function (result) {
if (result.isCancelled) {
console.log('Login was cancelled');
} else {
AccessToken.getCurrentAccessToken().then(
async (data) => {
const FBtoken = data.accessToken.toString();
await saveStorage('FBtoken', FBtoken);
const userFbInfo = await get(`https://graph.facebook.com/me?access_token=${FBtoken}&fields=id,name,picture,email,friendlists,birthday`);
await saveStorage('userFbInfo', JSON.stringify(
userFbInfo
));
context.props.goMainPage();
}
)
}
},
function (error) {
console.log('Login failed with error: ' + error);
}
);
}