1

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?

Ravindhiran
  • 5,304
  • 9
  • 50
  • 82

1 Answers1

0

How to get user info (email, name, etc.) from the react-native-fbsdk?

check outTry this solution out. It's pretty much exactly what you want

Ashrant Kohli
  • 73
  • 1
  • 9
  • i already referred above link but not getting email address. – Ravindhiran Jun 15 '17 at 06:04
  • https://github.com/magus/react-native-facebook-login/issues/176 Try this out. I think you have to log in to facebook before getting the email details or something of the sort. – Ashrant Kohli Jun 15 '17 at 06:15