Facebook JS Sdk - FB.getLoginStatus = undefined

dzm*_*dzm 9 facebook facebook-graph-api 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', 
                        }
                }); 
            }
            }); 
        };  
Run Code Online (Sandbox Code Playgroud)

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

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

谢谢你的帮助!

ste*_*eax 9

你在那里混合了OAuth和OAuth 2对象.将init设置为使用OAuth 2 oauth : true(建议所有应用必须在10月1日之前使用OAuth 2)并使用response.authResponse一致而不是response.session或使用OAuth 1并response.session始终如一地使用.如果你去OAuth 2,你还需要使用scope而不是perms你想要的权限.