我正在使用 facebook api 登录用户,它工作正常,但我在检索数据和使用后面的代码时遇到了一些麻烦。我尝试了一些解决方案,但没有任何效果。
到目前为止的代码
<script type="text/javascript">
// Load the SDK Asynchronously
(function (d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
} (document));
// Init the SDK upon load
window.fbAsyncInit = function () {
FB.init({
appId: 'MY_APP_ID',
channelUrl: 'MY_URL',
status: true,
cookie: true,
xfbml: true
});
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
// connected
} else if (response.status === 'not_authorized') {
// not_authorized
} else {
// not_logged_in
}
});
}
function login() {
FB.login(function (response) {
if (response.authResponse) {
retrieveInfo();
window.location.reload();
} else {
// cancelled
}
});
}
function retrieveInfo() {
FB.api('/me', function (response) {
var name = document.getElementById('name');
name.innerHTML = response.name;
var email = document.getElementById('email');
email.innerHTML = response.email;
});
}
</script>
<fb:login-button onlogin="login()" perms="email,user_about_me,user_birthday">Login com Facebook</fb:login-button>
<div align="center">
<div id="name"></div>
<div id="email"></div>
</div>
正如我所说,数据已被检索到,但我如何在后面的代码中使用它?