2012-07-27 61 views
7

對於我的生活,我無法獲得Event.subscribe('auth.authResponseChange')的工作。請參閱下面的代碼facebook FB.Event.subscribe('auth.authResponseChange')不起作用

<div id="fb-root"> 
    </div> 
    <script> 
     window.fbAsyncInit = function() { 
      FB.init({ 
       appId: 'XXXXXXXXXXXXXXX', // App ID 
       channelUrl: 'http://XXXXXXXX.us/', // Channel File 
       status: true, // check login status 
       cookie: true, // enable cookies to allow the server to access the session 
       xfbml: true // parse XFBML 
      }); 

      FB.Event.subscribe('auth.authResponseChange', function (response) { 
       alert('The status of the session is: ' + response.status); 
      }); 
     }; 


     // 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)); 
    </script> 
    <div class="fb-login-button" data-size="xlarge" scope="email" data-show-faces="false" 
     data-width="400" data-max-rows="1" autologoutlink="true"> 
     Login with Facebook</div> 

登錄按鈕呈現。我也可以註銷。唯一的問題是,auth.response更改不會觸發,我沒有收到「消息」彈出框

+0

FBML不久將被取消。最好不要使用它。 – InspiredJW 2012-07-27 10:03:49

+3

@InspiredJW FBML已經被棄用,這是XFBML,不會被棄用的東西 – 2012-08-07 02:16:07

+0

你有沒有試過根據文檔檢查'response [0]'?*請注意,在某些情況下,響應的值是不加鍵的,但當返回多個變量時,它包含相應的鍵。* => http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/ – PlantTheIdea 2013-10-29 21:55:18

回答

-4

您的fbAsyncInit函數是異步調用的,因此您不會看到任何警報消息。嘗試使用console.log來進行調試。

-1

你的代碼看起來不錯。

我會訪問您的Facebook應用程序,並特別檢查2個設置。

  1. 檢查「沙盒模式」 - 確保它被設置爲「已禁用」
  2. 檢查您的網站的URL和/或帆布網址 - 確保它們設置爲您的域名。 (也就是說,如果你在這個地方你的網址的工作應該是這個樣子http://localhost:#####/其中#####是你的端口。

希望有所幫助。

+0

嘿,你知道嗎?找出我的港口這個號碼? – LazerSharks 2013-06-26 03:00:26

+0

如果您在Visual Studio中工作,則從解決方案資源管理器中右鍵單擊您的Web項目,然後單擊屬性。在你的左邊,第三下,選擇Web。在服務器部分選擇'特定端口',並使用默認值或選擇一個新的。 – KevinM 2013-07-04 21:15:37