Question

So, I have created your standard facebook test app. It has the javascript SDK loading block and the following code after it:

window.fbAsyncInit = function()
{
    console.log('initiating FB');
    FB.init({
        appId:      appID,
        status:     true, // check login status
        cookie:     true, // enable cookies to allow the server to access the session
        xfbml:      true  // parse XFBML
    });

    FB.Event.subscribe(
        'auth.authResponseChange',
        function(response)
        {
            console.log('authResponseChange', response);
            if (response.status === 'connected')
            {
                console.log('logged in');
            }
            else
            {
                console.log('not logged in');
            }
        }
    );
};

The problem: with my dev account, every console.log() is logged, as expected. With a different account not in any way related to the app it only logs 'initiating FB', and nothing after that, even though status: true. Why is this happening?

Était-ce utile?

La solution

That's fine, since there's no change in the state.

The auth.authResponseChanged event is fired when the auth response has changed. The authResponse is part of the response object that's returned when querying the state of a person's authentication status. It contains the person's access token, when the token will expire and the person's user ID.

For an app user, when you run the app- status is changed to login since you have set status: true, so this event is triggered and you got logged in and come to the session.

But when you run the app for a not-logged-in/non-app user, this event wont trigger since the status is not changed. It was "not-logged-in" or "not-authorized" earlier and its the same now.

When you call facebook login for a not-logged-in user/non-app user, the status will change and you will see a your log as "logged in" or "not logged in".

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top