Facebook JS Sdk - FB.getLoginStatus = undefined

时间:2011-08-28 21:03:55

标签: facebook-graph-api facebook facebook-javascript-sdk

我正在使用Facebook的JavaScript SDK并尝试确定用户是否已登录,我有以下代码:

        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', 
                        }
                }); 
            }
            }); 
        };  

getLoginStatus的response.AuthResponse是'undefined',但我实际上是使用为此应用设置的权限登录的。

知道为什么它会继续显示为未定义?当我再次尝试登录时,它只关闭了Facebook框(因为我已登录)并刷新页面,再次显示“未定义”。

感谢您的帮助!

1 个答案:

答案 0 :(得分:9)

您正在混合使用OAuth和OAuth 2对象。使用oauth : true(建议为all apps must use OAuth 2 by Oct 1)将init设置为使用OAuth 2并始终使用response.authResponse而不是response.session或使用OAuth 1并使用response.session一致。如果您转到OAuth 2,则还需要使用scope而不是perms来获取所需的权限。