react-native-fbsdk:如何获取电子邮件,名字,姓氏等用户信息?

时间:2017-06-15 05:50:03

标签: facebook react-native react-native-fbsdk

当用户使用Facebook进行身份验证时,我尝试访问用户的电子邮件和名称以进行设置和帐户。我已经准备好了react-native-fbsdk的文档,但我只获得了accessstoken,userID,name,但获取了电子邮件地址。

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);
}
);
}

我在下面提到了链接,但没有收到电子邮件地址:How to get user info (email, name, etc.) from the react-native-fbsdk?

1 个答案:

答案 0 :(得分:0)

如何从react-native-fbsdk获取用户信息(电子邮件,姓名等)?

检查出来试试这个解决方案。这几乎就是你想要的东西