gruszczy
gruszczy

Reputation: 42168

Facebook: Javascript API sometimes doesn't load

Once every several times the calls to the Facebook API are not finished (or maybe not even made). For example I am counting the number of user's friends, that also use my app, but this seems to be never calculated. I tried to investigate this issue, but there are no errors in the Chrome console. Have you ever encountered such behavior and know, how to fix it?

EDIT

Here are some details, I get:

error_code 190
error_msg Error validating access token: The session is invalid because the user logged out or because auth.expireSession was invoked

The point is I am logging out as one user and then logging in as another. Why is it then Facebook treating it as a logged out user? Furthermore, everything works, if I then refresh the page.

EDIT2

This are some code snippets:

function facebookInit(config) {
  Config = config;

  FB.init({
    appId: Config.appId,
    xfbml: true,
    status: true,
    cookie: true,
    channelUrl:
      window.location.protocol + '//' + window.location.host + '/channel.html'
  });
  FB.Event.subscribe('auth.sessionChange', handleSessionChange);
  FB.Canvas.setSize();

  // ensure we're always running on apps.facebook.com
  if (window == top) { goHome(); }
}


window.fbAsyncInit = function() { 
    facebookInit({{ js_conf|safe }}) 
    afterSDK()  
};

and the problem arises here:

var query = "SELECT '' " +
        "FROM user " +
        "WHERE is_app_user = \"1\" AND " +
              "uid IN (SELECT uid2 " +
                      "FROM friend WHERE uid1 = {{ user.user_id }})"
FB.api({'method': 'fql.query', 'query': query}, 
       function(response){

This code is called inside afterSDK() function. The response might bring error, rather than the number of friends using app.

Upvotes: 2

Views: 1658

Answers (1)

Soatl
Soatl

Reputation: 10582

Let me take a stab at this.

I think the issue is because your logging out a user, and logging in another. There may be an issue occurring because Facebook does not detect that the other user has logged out, and thinks its the same person. This may clear up that issue:

FB.logout(function(response) {
  // user is now logged out
});

Run that to ensure the user is logged out, then try to move from there

Hopefully this helps a little bit.

Here is the facebook logout method

You can also look at this previous SO question about refreshing a session (though its in PHP and i don't know the JS equivalent)

Upvotes: 1

Related Questions