简体   繁体   中英

See if user logged on to facebook

I'm trying to use facebook API to see if user is logged on from my site.

When I call FB.getLoginStatus I get no response. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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