Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FB.getLoginStatus() not working

I am trying to write a code that checks whether the user is logged in or not, and found that there is a built-in method in FBJS API, which is called getLoginStatus()

I have implemented it inside of html, but for some how, alert() inside of the getLoginStatus() is not fired.

I have also tried to add channelUrl at init(),but it still does the same.

Below is the code that I have written.

Can anyone help me with it?

Thanks in advance!

<!-- Initialize FB API for use -->
    <div id="fb-root"></div>
    <script type="text/javascript"> 
    //var curLoc = window.location;
    //var chanURL = curLoc.protocol + "//" + curLoc.hostname + ":" + 
    //curLoc.port + "/channel.html"


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

            FB.getLoginStatus(function(response) {
                  if (response.session) {
                    // logged in and connected user, someone you know
                    alert('logged in');
                  } else {
                    // no user session available, someone you dont know
                    alert('not logged in');
                  }
            });
        };
        (function() {
            var e = document.createElement('script');
            e.type = 'text/javascript';
            e.src = document.location.protocol +
                '//connect.facebook.net/en_US/all.js';
            e.async = true;
            document.getElementById('fb-root').appendChild(e);
        }());
    </script>
like image 647
darangho Avatar asked Aug 31 '11 00:08

darangho


2 Answers

I had this the other day and the problem was that I was NOT logged in in Facebook AND my App was in Sandbox mode. Maaaaybe it's the same here, longshot but wanted to suggest it anyway.

Note: Comparable combinations that wouldn't work are being logged in in Facebook as a Test user that has no access to the application in question or being logged in in Facebook as a non-test/non-admin user AND having the app in sandbox mode.

like image 192
Jochem Avatar answered Oct 25 '22 09:10

Jochem


BTW. They changed it again. It is now:

response.authResponse

and not response.session anymore.

like image 44
saurabhj Avatar answered Oct 25 '22 08:10

saurabhj