Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.AuthResponse 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!

like image 427
dzm Avatar asked Aug 28 '11 21:08

dzm


1 Answers

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.

like image 156
steveax Avatar answered Oct 04 '22 01:10

steveax