2013-01-07 28 views
0

以下代碼在Firefox或IE中似乎不起作用,但在Chrome中運行良好。我希望有人能夠對我做錯了什麼有所瞭解。它用於在Facebook畫布中運行統一遊戲。getLoginStatus()在Firefox中沒有得到響應/ ie

<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,我「獲得登錄狀態」後得到任何消息。

謝謝, Andrew。

回答

0

試試你的Additional initialization code內這 -

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

    // your code 

} 
+0

感謝您的答覆。添加這樣的結果是沒有來自firefox/ie的日誌消息,但是在Chrome中沒有任何更改。所以看起來好像firefox/ie沒有獲取FB對象。不太清楚爲什麼。 –