2011-08-28 62 views
8

我使用Facebook的JavaScript的SDK,並試圖確定用戶是否登錄或沒有,我有以下代碼:Facebook的JS SDK - FB.getLoginStatus =未定義

 window.fbAsyncInit = function() {  
      FB.init({ 
       appId:'139894666087975', cookie:true, status:true, xfbml:true 
      }); 

      $('.login_fb').click(function(){ 
       FB.login(function(response) { 
       if(response.session) 
       { 
        if (response.perms) { 
         window.location.reload(); 
        } 
       } 
       },{perms:'email,user_birthday,user_hometown,user_location,publish_stream'}); 
      }); 

      FB.getLoginStatus(function(response) { 
             alert(response.authResponse); 
       if (response.authResponse) { 
        alert(response.authResponse); 
       } else { 
       $.blockUI({ 
        message: $('#fblogin'), 
        css: { 
         top: '9%', 
         left: ($(window).width() - 700) /2 + 'px', 
         width: '700px', 
         cursor: 'hand', 
         border: '10px solid #ccc', 
         } 
       }); 
      } 
      }); 
     }; 

的response.AuthResponse爲getLoginStatus是'未定義',但我實際上是使用爲此應用程序設置的權限登錄的。

任何想法爲什麼它會繼續顯示爲undefined?當我嘗試再次登錄時,它僅關閉Facebook框(因爲我已經登錄)並刷新頁面,再次顯示「未定義」。

感謝您的幫助!

回答

8

您正在混合OAuth和OAuth 2對象。或者將init設置爲使用oauth : true(推薦爲all apps must use OAuth 2 by Oct 1),並始終使用response.authResponse而不是response.session,或者使用OAuth 1並使用response.session來始終使用OAuth 2。如果您轉到OAuth 2,那麼您還需要使用scope而不是perms來獲得所需的權限。

+0

我永遠不會想到這是一個修復!哇,謝謝史蒂夫! – iUsable