I'm using bleeding edge versions of 7-dev, straight from github.

I can't get this thing to work reliably -- and I mostly blame Facebook.

When I log into Facebook using the "connect" button, I can log in into Facebook. But sometimes the popup window closes itself, and sometimes it stays open but turns blank.

I'm sure that's Facebook's problem... It shows to me that the system Facebook used to circumvent cross-site and cross-window scripting, using a Flash object which doesn't have the same limitations as the browser (until Adobe patches it, that is), apparently just is not reliable at all.

But the main window only refreshes itself, as it should, in MSIE. I have to manually reload it in my other browsers (Firefox, Chrome, Opera, Safari). The event handler:

          FB.Event.subscribe(\'auth.login\', function() {
            window.location.reload();
          });

is apparently never called. Ditto when I when I log out of Facebook in another window, for this other event:

          FB.Event.subscribe(\'auth.logout\', function(response) {
            window.location.reload();
          });

But it gets a lot worse. Sometimes, if I manually reload my Drupal page after logging out of Facebook, by pressing F5, it reloads... and reloads...and reloads, ad infinitum. Apparently now that same event gets triggered every time that page is reloaded.

I've had this happen to me both in Firefox and MSIE9... But now it no longer happens (though Firefox my still reloads twice before it stops). What could have been causing this issue? A stale cache?

And could we wrap a condition around the action of that event handler to prevent it from happening? For example comparing a user identifying value on the server with the current value in Javascript: they should sync up after 1 reload.

Not that I have a good idea where the server could get that value from... Perhaps a parameter in the URL, added using Javascript.

Alternatively, since the idea is to update the Facebook login block, we could do just that... using Ajax?

Comments

Opensoft’s picture

Use the following code to resolve the issue starting line 532 in fbconnect.module

// whenever the user logs in, we tell our login service
FB.Event.subscribe(\'auth.login\', function() {
window.location.reload();
});
FB.Event.subscribe(\'auth.logout\', function(response) {
// window.location.reload();
status: "Logged out";
});

bartl’s picture

Thanks for the reply. I have not yet resolved every issue, but your response is in line with what I've discovered myself, thus far. The endless loop is indeed that "auth.logout" event that gets triggered when the page loads. But I don't understand what you mean with "status: "Logged out";", I would think that that is invalid Javascript.

Anyway, just reloading the page doesn't do as much as intended. If you log out of Facebook, the Drupal site still thinks that you are connected to Facebook, and I think that is likely due to a cache of the Facebook status in the facebook-php-sdk library.

I think to properly function, it may indeed be necessary to go the Ajax route. If you check the FB object in client side Javascript, you'll notice that it is not unlikely that Javascript your Facebook status is different, from what the Drupal/PHP side thinks it is. So it might be beneficial to use Ajax to inform the server that the Facebook status has changed, and possibly without reloading the web page because that is unnecessary. After all, the only thing that ought to change on the page is the Facebook login block. So an URL under fbconnect that only returns the Facebook block might do the trick (with a parameter indicating the actual status), and with jQuery it's easy to replace the HTML of that block.