Check if a user is logged in to Facebook
I'm trying to check whether a user is logged in to Facebook (just logged in or not, with no relation to my application) us开发者_Go百科ing javascript.
I tried using the following code after FB.init:FB.getLoginStatus(function(response) {
alert(response.status);
});
edge.create is working just fine though.There are some hacks that can help, but not in your situation. https://grepular.com/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.com/ajax/composer/attachment/question/question.php" onload="logged()" onerror="notlogged()">
</body>
</html>
if (FB.getSession() != null) {
FB.api('/me', function(response){
alert ("Welcome " + 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.com/docs/guides/web/
FB.getLoginStatus(function(response) {
if (response.authResponse) {
// alert('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
alert('Good to see you, ' + response.name + '.');
});
}
});
精彩评论