【发布时间】:2018-05-01 21:34:28
【问题描述】:
我正在使用 react-native-fbsdk。我想在用户注册应用程序时向用户显示用户名和电子邮件,以便为应用程序创建配置文件,但未显示任何数据。如何获取这些数据以及如何在不同的屏幕上显示它。
这是我的代码
import FBSDK from 'react-native-fbsdk'
import { LoginButton,AccessToken,GraphRequest,GraphRequestManager} from 'react-native-fbsdk';
const {
LoginManager,
} = FBSDK;
<LoginButton
readPermissions={['public_profile']}
onLoginFinished={
(error, result) => {
if (error) {
alert("login has error: " + result.error);
} else if (result.isCancelled) {
alert("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
(data) => {
const infoRequest = new GraphRequest(
'/me?fields=name,picture',
null,
this._responseInfoCallback
);
// Start the graph request.
new GraphRequestManager().addRequest(infoRequest).start();
}
)
}
}
}
onLogoutFinished={() => alert("logout.")}/>
</View>
);
}
_responseInfoCallback = (error, result) => {
if (error) {
alert('Error fetching data: ' + error.toString());
} else {
alert('Result Name: ' + result.name);
}
}
}
感谢朋友
【问题讨论】:
标签: facebook facebook-graph-api react-native fbsdk react-native-fbsdk