我正在尝试编写一段代码来检查用户是否已登录,发现FBJS API中有一个内置方法称为getLoginStatus()。
我已经在HTML中实现了它,但不知何故,在getLoginStatus()中的alert()未被触发。
我还尝试在init()中添加channelUrl,但仍然是同样的情况。
以下是我编写的代码。
有人可以帮我吗?
提前感谢!
<!-- Initialize FB API for use -->
<div id="fb-root"></div>
<script type="text/javascript">
//var curLoc = window.location;
//var chanURL = curLoc.protocol + "//" + curLoc.hostname + ":" +
//curLoc.port + "/channel.html"
window.fbAsyncInit = function() {
FB.init({appId: '####', status: true, cookie: true, xfbml: true});
FB.getLoginStatus(function(response) {
if (response.session) {
// logged in and connected user, someone you know
alert('logged in');
} else {
// no user session available, someone you dont know
alert('not logged in');
}
});
};
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>