简体   繁体   English

查看用户是否登录到Facebook

[英]See if user logged on to facebook

I'm trying to use facebook API to see if user is logged on from my site. 我正在尝试使用facebook API查看用户是否从我的网站登录。

When I call FB.getLoginStatus I get no response. 当我调用FB.getLoginStatus时,我没有任何响应。 I tried about every example code i saw to get a response and got nothing. 我尝试了所有看到的示例代码,但得到响应却一无所获。 Could someone please help me figure out the problem with my code: 有人可以帮我找出我的代码存在的问题:

<div id="fb-root"></div>
<script type="text/javascript" src="//connect.facebook.net/en_US/all.js">
<script type="text/javascript">   
       window.fbAsyncInit = function() {
          FB.init({
            appId      : 'my_app_id', // App ID
            status     : true, // check login status
            cookie     : true, // enable cookies to allow the server to access the session
            xfbml      : true  // parse XFBML
          });
        };

        // Load the SDK Asynchronously
        (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));
    function GetFBLoginStatus() {
    debugger;
    window.fbAsyncInit()
            alert("get status");
    FB.getLoginStatus(function(response) {
        alert("inside call back function"); 
        if (response.status === 'connected') {
        alert("logged in");
        } else if (response.status === 'not_authorized') { 
            alert("not authorized"); 
        } else {
            alert("logged out");
        }
        return true;
    }, true)
} 
</script> 

There is no closing tag for your first script: 您的第一个脚本没有结束标记:

<script type="text/javascript" src="//connect.facebook.net/en_US/all.js">

Should be 应该

<script type="text/javascript" src="//connect.facebook.net/en_US/all.js"></script>

Right now the browser is thinking the second script tag is part of the script being defined in your first script tag. 现在,浏览器认为第二个脚本标签是第一个脚本标签中定义的脚本的一部分。 You get parsing errors and the rest isn't executed. 您会遇到解析错误,而其余的则不会执行。

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

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