最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Check if a user is logged in to Facebook - Stack Overflow

programmeradmin1浏览0评论

I'm trying to check whether a user is logged in to Facebook (just logged in or not, with no relation to my application) using javascript.
I tried using the following code after FB.init:
FB.getLoginStatus(function(response) {
alert(response.status);
});

edge.create is working just fine though.

I'm trying to check whether a user is logged in to Facebook (just logged in or not, with no relation to my application) using javascript.
I tried using the following code after FB.init:
FB.getLoginStatus(function(response) {
alert(response.status);
});

edge.create is working just fine though.

Share Improve this question asked Apr 13, 2011 at 19:25 LiorLior 5,6849 gold badges32 silver badges38 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

There are some hacks that can help, but not in your situation. https://grepular./Abusing_HTTP_Status_Codes_to_Expose_Private_Information

Here is simple example:

<html> 
<head> 

</head>

<body>
// At the end of page will be good 
<script>
function logged() {
    alert('logged');
}
function notlogged() {
    alert('not logged');
}
</script>
<script src="http://www.facebook./ajax/poser/attachment/question/question.php" onload="logged()" onerror="notlogged()">
</body> 
</html> 
if (FB.getSession() != null) {
    FB.api('/me', function(response){
        alert ("Wele " + response.name);
    })
}

With one caveat, though: the user needs to authorize your app in order to detect whether is logged in or not. I believe there is no way to detect it without it with this api: You can add a like button and such, but not interact with the fb status.

http://developers.facebook./docs/guides/web/

FB.getLoginStatus(function(response) {
if (response.authResponse) {
                // alert('Wele!  Fetching your information.... ');
                 FB.api('/me', function(response) {
                   alert('Good to see you, ' + response.name + '.');
                   });
               }
});
发布评论

评论列表(0)

  1. 暂无评论