Failed to get facebook login status

I am new to facebook app development. I am trying to get an access token from facebook. For this I am trying to check my login status using the following code

<html>
<body>
 <fb:login-button></fb:login-button>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript"> 
window.fbAsyncInit = function() {
    FB.init({appId: 'appId', status: true, cookie: true, xfbml: true});
    alert('page 1');
    FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
        alert('Page 2');
        // connected
      } else if (response.status === 'not_authorized') {
        // not_authorized
      } else {
        // not_logged_in
      }
     });
}
</script>
</body>
</html>

      

When I execute the above code, it shows a login button where I can login successfully. I can get the "Page 1" warning, but I cannot get the "Page 2" warning. I don't know what happened with this code.

Thank.

+3


source to share


2 answers


Check if the app is included in the app Sanbox mode. If so, and if you are not logged in as a user who has an admin or developer role for this application, this will happen. Try if it works after shutting down Sandbox for a while. Check out the answer to this question - fooobar.com/questions/1064451 / ...



Of course, I assume the part appId: 'appId'

is an example and you have the correct app ID in the code taken from the app settings.

+2


source


A few tips to help you:

1) Check if your appID is valid (I hope you literally don't write appId

and actually pasted the app file you registered)

FB.init({appId: 'appId', status: true, cookie: true, xfbml: true});

2) try looking at the actual answer by running:



alert(response);

* Answer details are given here: https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

But I am assuming that your application is not registered correctly or that you did not enter the correct appID in the field appId

. This is usually the case.

0


source







All Articles