Facebook-Login with React Native不返回预期数据

问题描述 投票:0回答:1

当我使用FBSDK包装器登录我的用户时,我使用:

LoginManager.logInWithReadPermissions(['public_profile', 'email']).then(result => {

  // find user information here if accepted

});

我确实在响应中找到了电子邮件地址,也找到了用户的photoURL。但是,我真的需要单独的名字和姓氏。我刚刚得到一个名为displayName的属性,它在一个字符串中包含名字和姓氏。

我不想做一些hacky事情,比如拆分字符串的第一个空格来获得名字,因为它不会一直工作(用户可以有一个中间名?)。

Facebook确实指定你根据first_name获得一个名为last_namethe official docs的字段。

任何人都知道如何可靠地获取用户的名字和姓氏?

谢谢!

facebook react-native facebook-javascript-sdk
1个回答
1
投票

您需要询问您想要获得的字段,否则您将只获得默认字段。例如,您可以使用此API调用获取first_name和last_name字段:

const infoRequest = new GraphRequest('/me', {
    parameters: {
        fields: {
            string: 'first_name,last_name'
        }
    }
}, (error, result) => {
    if (error) {
        console.log('Error fetching data: ' + error.toString());
    } else {
        console.log('Success fetching data: ' + result.toString());
    }
});
new GraphRequestManager().addRequest(infoRequest).start();
© www.soinside.com 2019 - 2024. All rights reserved.