0

以下代码在 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 中我才能在“获取登录状态”之后收到任何消息。

谢谢,安德鲁。

4

1 回答 1

0

试试你的Additional initialization code这个-

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

    // your code

}
于 2013-01-07T06:35:34.460 回答