2014-10-10 171 views
2

所以,我最近创建了一个FB,可供所有用户使用,并且据我所知,不在沙箱模式。我使用了FB开发人员网站上的文档中提供的示例代码,并将其放在本地主机上。设置“应用程序域”和“网站URL”都是正确的。所以,即使当我登录到FB,在登录,在Chrome的JS控制台,它读取statusChangeCallback splash.php:60 Object {status: "unknown", authResponse: null}Facebook登录流量返回状态“unknown”

我用下面的代码

<script> 
    // This is called with the results from from FB.getLoginStatus(). 
    function statusChangeCallback(response) { 
     console.log('statusChangeCallback'); 
     console.log(response); 

     if(response.status === 'connected') { 
      testAPI(); 
     } else if(response.status === 'not_authorized') { 
      document.getElementById('status').innerHTML = 'Please log ' + 'into this app.'; 
     } else { 
      document.getElementById('status').innerHTML = 'Please log ' + 'into Facebook.'; 
     } 
    } 

    // This function is called when someone finishes with the Login 
    // Button. See the onlogin handler attached to it in the sample 
    // code below. 
    function checkLoginState() { 
     FB.getLoginStatus(function(response) { 
      statusChangeCallback(response); 
     }); 
    } 

    window.fbAsyncInit = function() { 
     FB.init({ 
      appId: "I'm not dumb", 
      //cookie: true, 
      status: true, 
      xfbml: true, 
      oauth: true, 
      version: 'v2.1' 
     }); 

     FB.getLoginStatus(function(response) { 
      alert(response); 
      if(response.status === 'connected') { 
      if(response.authResponse != 'undefined') { 
        window.location = '<?php echo $base_url; ?>register'; 
         } 
      } else if(response.status === 'not_authorized') { 
         // it means we have a user but he hasn't granted any permissions to our app 
         // we're going to redirect him to the permission page 
      } else { 
         //the user is not logged in, as you already have a login button you don't have to do nothing 
      } 
     }); 

     FB.Event.subscribe('auth.login', function(response) { 
      window.location = '<?php echo $base_url; ?>register'; 
     }); 

     FB.getLoginStatus(function(response) { 
      statusChangeCallback(response); 
     }); 
    }; 

    // Load the SDK asynchronously 
    (function(d, s, id) { 
     var js, fjs = d.getElementsByTagName(s)[0]; 
     if (d.getElementById(id)) return; 
     js = d.createElement(s); js.id = id; 
     js.src = "//connect.facebook.net/en_US/sdk.js"; 
     fjs.parentNode.insertBefore(js, fjs); 
    } (document, 'script', 'facebook-jssdk')); 

    // Here we run a very simple test of the Graph API after login is 
    // successful. See statusChangeCallback() for when this call is made. 
    function testAPI() { 
     console.log('Welcome! Fetching your information.... '); 

     FB.api('/me', function(response) { 
     console.log('Successful login for: ' + response); 
     document.getElementById('status').innerHTML = 'Thanks for logging in, ' + response + '!'; 
    }); 
    } 
</script> 

<fb:login-button scope="" onlogin="checkLoginState();"></fb:login-button> 
<div id="status"></div> 

我绝对不知道为什么发生这种情况,我”以前从未遇到过这个问题。

+0

你为什么要叫'FB.getLoginStatus()'两次找? – 2014-10-17 09:01:55

回答