开发者

Facebook JS Sdk - FB.getLoginStatus = undefined

I'm using Facebook's JavaScript SDK and trying to determine if the user is logged in or not, I have the following code:

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

The response.A开发者_StackOverflow中文版uthResponse for getLoginStatus is 'undefined', but I am actually logged in with permissions set for this app.

Any idea why it would continue to show as undefined? When I try to login again, it just closes the Facebook box (because I'm already logged in) and refreshes the page, again showing 'undefined'.

Thanks for any help!


You're mixing OAuth and OAuth 2 objects in there. Either set the init to use OAuth 2 using oauth : true (recommended as all apps must use OAuth 2 by Oct 1) and use response.authResponse consistently rather than response.session or go with OAuth 1 and use response.session consistently. If you go to OAuth 2, you'll also need to use scope rather than perms for the permissions you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜