简体   繁体   English

检查用户是否登录Facebook

[英]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) using javascript. 我正在尝试使用JavaScript检查用户是否已登录Facebook(是否已登录,与我的应用程序无关)。
I tried using the following code after FB.init: 我尝试在FB.init之后使用以下代码:
FB.getLoginStatus(function(response) {
alert(response.status);
});

edge.create is working just fine though. edge.create工作正常。

There are some hacks that can help, but not in your situation. 有一些技巧可以帮助您,但在您遇到的情况中不起作用。 https://grepular.com/Abusing_HTTP_Status_Codes_to_Expose_Private_Information 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. 我相信,如果没有此api,没有它就无法检测到它:您可以添加like按钮等等,但不能与fb状态交互。

http://developers.facebook.com/docs/guides/web/ 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 + '.');
                   });
               }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM