2013-10-11 155 views
2

以下代碼來自官方Facebook開發人員頁面,適用於FF和Safari,有時適用於Chrome - 但更多情況下不適用於Chrome。Facebook JavaScript API - Chrome中的登錄失敗

在帶有最新Chrome的Snow Leopard上,我點擊登錄按鈕並在FB登錄對話框打開和關閉時看到一點閃爍。如果在我的FB賬戶中,我刪除並重新添加應用程序,我會被要求提供權限,但事件似乎從未觸發。

有誰知道這是否是一個錯誤,或者我可能會找到一個解決方案,不需要我手動輪詢服務器?

這是Google+還是Facebook的產品?

<html> 
<head></head> 
<body> 
<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
    FB.init({ 
      appId  : $APP_ID$,     // App ID from the app dashboard 
      channelUrl : $channelUrl$,    // Channel file for x-domain comms 
      status  : true,      // Check Facebook Login status 
      cookie  : true, 
      oauth  : true, 
      xfbml  : true      // Look for social plugins on the page 
    }); 

    // Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired 
    // for any authentication related change, such as login, logout or session refresh. This means that 
    // whenever someone who was previously logged out tries to log in again, the correct case below 
    // will be handled. 
    FB.Event.subscribe('auth.authResponseChange', function(response) { 
    console.log('auth.authResponseChange fired'); 
    // Here we specify what we do with the response anytime this event occurs. 
    if (response.status === 'connected') { 
     // The response object is returned with a status field that lets the app know the current 
     // login status of the person. In this case, we're handling the situation where they 
     // have logged in to the app. 
     testAPI(); 
    } else if (response.status === 'not_authorized') { 
     // In this case, the person is logged into Facebook, but not into the app, so we call 
     // FB.login() to prompt them to do so. 
     // In real-life usage, you wouldn't want to immediately prompt someone to login 
     // like this, for two reasons: 
     // (1) JavaScript created popup windows are blocked by most browsers unless they 
     // result from direct interaction from people using the app (such as a mouse click) 
     // (2) it is a bad experience to be continually prompted to login upon page load. 
     FB.login(); 
    } else { 
     // In this case, the person is not logged into Facebook, so we call the login() 
     // function to prompt them to do so. Note that at this stage there is no indication 
     // of whether they are logged into the app. If they aren't then they'll see the Login 
     // dialog right after they log in to Facebook. 
     // The same caveats as above apply to the FB.login() call here. 
     FB.login(); 
    } 
    }); 
    }; 

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

    // Here we run a very simple test of the Graph API after login is successful. 
    // This testAPI() function is only called in those cases. 
    function testAPI() { 
    console.log('Welcome! Fetching your information.... '); 
    FB.api('/me', function(response) { 
     console.log('Good to see you, ' + response.name + '.'); 
    }); 
    } 
</script> 

<!-- 
    Below we include the Login Button social plugin. This button uses the JavaScript SDK to 
    present a graphical Login button that triggers the FB.login() function when clicked. 

    Learn more about options for the login button plugin: 
    /docs/reference/plugins/login/ --> 

    <!-- scope='publish_stream,read_stream' --> 
<fb:login-button show-faces="true" width="200" max-rows="1"></fb:login-button> 
</body> 
</html> 
+0

Windows XP Chrome報告FB JS SDK代碼中有關http/https協議不匹配的錯誤 - 將FB'連接'URI從'//'更改爲'https '沒有任何區別。 – LeeGee

回答

3

進入chrome設置 - 高級設置;在隱私下點擊「內容設置」。查看是否選中「阻止第三方Cookie和網站數據」。

我有一個類似的問題,其中鉻在js-sdk會給我瞬間fb彈出窗口,但實際上似乎沒有登錄用戶或識別用戶登錄/授權。就我而言,我認爲我已將問題縮小到了該設置。

如果您啓用了該功能,請嘗試禁用該功能以查看是否爲您解決了這個問題......雖然這只是一個診斷步驟,但它不是解決方案,因爲您仍然擁有啓用該設置的用戶。

我試圖確定解決辦法如有可能..涉及使用FB登錄流程「爲網頁」(即不使用他們的SDK,從而有可能避免使用第三方Cookie的)

這裏是我的這個問題的版本的帖子... can facebook javascript/php SDK's "talk" to each other if 3rd-party cookies are disabled? facebook->getUser() returns 0

+0

我的解決方法是使用onClick事件觸發FB.login提供我自己的按鈕。我懷疑如果所有東西都託管在hTTPS服務器上,這顯然現在是FB的要求(截至10月1日),這一切都會好起來的。 – LeeGee