当用户通过 Facebook 进行身份验证时,我正在尝试访问用户的电子邮件和姓名以设置和帐户。我已经准备好了 react-native-fbsdk 的文档,但我只得到了 accesstoken 、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);
}
);
}
我参考了下面的链接,但没有获取电子邮件地址:如何从 react-native-fbsdk 获取用户信息(电子邮件、姓名等)?