getLoginStatus()没有得到firefox / ie中的响应

时间:2013-01-07 06:06:35

标签: facebook firefox

以下代码在Firefox或IE中似乎不起作用,但在Chrome中运行良好。我希望有人可能对我做错了什么有所了解。它用于在Facebook画布上运行统一游戏。

<script type='text/javascript'>
var appID = 'xxxxxxxxxxxxxxxxxxx';
var connected = false;
var loggedin = false;
var purchaseResult = "Failed";
var inviteResult = "Failed";

window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
  appId      : appID, // App ID from the App Dashboard
  status     : true, // check the login status upon init?
  cookie     : true, // set sessions cookies to allow your server to access the session?
  oauth      : true, // enable OAuth 2.0
  frictionlessRequests : true,
  xfbml      : false  // parse XFBML tags on this page?
});

// Additional initialization code such as adding Event Listeners goes here
//Get the current login status.
document.getElementById("text").innerText = "Getting login status";
console.log("Getting login status");
    FB.getLoginStatus(function(response) {
      console.log("got response");
      var user_box = document.getElementById("login");
      //document.getElementById("text").innerText = "Got response: " + response.status;
  if (response.status === 'connected') {
    // the user is logged in and has authenticated your
    // app, and response.authResponse supplies
    // the user's ID, a valid access token, a signed
    // request, and the time the access token 
    // and signed request each expire
    var uid = response.authResponse.userID;
    console.log("Getting login status returned user id: " + uid);
    var accessToken = response.authResponse.accessToken;
    //user_box.style.visibility = 'hidden';
    loggedin = true; 
    //document.write("Connected to facebook");
  } else if (response.status === 'not_authorized') {
    // the user is logged in to Facebook, 
    // but has not authenticated your app
    user_box.style.display = 'block';
    FB.Event.subscribe('auth.login', function(response) {
      // Let unity know the user has logged in
      GetCurrentUser();
      user_box.style.display = 'none';
    });
  } else {
    // the user isn't logged in to Facebook.
    FB.Event.subscribe('auth.login', function(response) {
      // Let unity know the user has logged in
      GetCurrentUser();
      user_box.style.display = 'none';
    });
    user_box.style.display = 'block';
  }

  if (loggedin) {
    GetCurrentUser();
  }
}, true);
};

我在那里有日志消息来检查发生了什么,但是只有在Chrome中我才能在“获取登录状态”后收到任何消息。

谢谢, 安德鲁。

1 个答案:

答案 0 :(得分:0)

在此处尝试Additional initialization code -

if (typeof(FB) != 'undefined' && FB != null )
{

    // your code

}