我在react native中使用fbsdk。我能够获得Facebook登录页面。但是我希望当我单击登录时,它会从Facebook提取年龄,名字,性别等详细信息并显示出来。
这是Facebook登录的代码。
App.js
import React, { Component } from 'react';
import { View } from 'react-native';
import { LoginButton, AccessToken } from 'react-native-fbsdk';
export default class Login extends Component {
render() {
return (
<View>
<LoginButton
onLoginFinished={
(error, result) => {
if (error) {
console.log("login has error: " + result.error);
} else if (result.isCancelled) {
console.log("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
(data) => {
console.log(data.accessToken.toString())
}
)
}
}
}
onLogoutFinished={() => console.log("logout.")}/>
</View>
);
}
});
我需要在此代码中添加所有内容,以便从facebook获取详细信息并显示它。
答案 0 :(得分:0)
您需要从LoginManager
导入react-native-fbsdk
,并在onclick函数上使用以下代码
LoginManager.logInWithReadPermissions(["details_you_need_from_logged_in_profile"]).then(
function(result) {
if (result.isCancelled) {
console.log("Login was Cancelled");
} else {
console.log(
"Login was a Success" + result.grantedPermissions.toString()
);
}
},