I'm trying to access the user's email and name to setup and account when a user authenticates with Facebook. I've ready the documentations for react-native-fbsdk but I'm getting only accesstoken ,userID,name but getting email address.
facebookLoginTapped()
{
LoginManager.logInWithReadPermissions(['email']).then(
function(result) {
if (result.isCancelled) {
alert('Login was cancelled');
} else {
alert('Login success with permissions: ' + JSON.stringify(result));
AccessToken.getCurrentAccessToken().then((data) => {
const { accessToken } = data
fetch(`https://graph.facebook.com/me?access_token=${data.accessToken.toString()}`)
.then((response) => response.json())
.then((res) => {
var socialOptions = {
email: res.email,
firstName: res.first_name,
lastName: res.last_name,
token: data.accessToken.toString(),
uid: data.userID,
loginType: 'facebook',
}
alert(JSON.stringify(socialOptions
))
// ignore this--custom api call sending the data to my own api
api.socialRegister(socialOptions)
.then((response) => {
// working
this.handleResponse(response);
})
.catch((error) => console.log('error', error))
})
.catch((err) => console.log('error occurred', err.message));
})
}
},
function(error) {
alert('Login failed with error: ' + error);
}
);
}
i referred below link but not getting email address : How to get user info (email, name, etc.) from the react-native-fbsdk?