<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '261852174300349',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
//LOGIN FUNCTION
function login() {
FB.getLoginStatus(function(response) {
console.log(response)
});
}
</script>
<div onclick="login();">Login with Facebook</div>
根据facebook文档检查用户是否已经登录我们可以使用FB.getLoginStatus
获取用户是否登录但是在我的原因我无法得到任何回复
答案 0 :(得分:0)
试试这个。它将在初始化后立即调用登录功能。在您当前的代码中
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '261852174300349',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
//LOGIN FUNCTION
function login() {
FB.getLoginStatus(function(response) {
console.log(response)
});
}
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<div onclick="login();">Login with Facebook</div>