In my code, I have this sequence:
...
FB.Connect.requireSession();
FB.Facebook.get_sessionWaitable().waitUntilReady( function( session ) {
window.location.reload();
} );
I would expect when the waitUntilReady callback was activated, the <api_key>_* cookies would be set.
It appears they are not, though until after the requireSession activated by the reload. For my server to see the cookies, I've been having reload the page again.
Is there a way I can get the cookies set before the reload happens?
Offline
The cookies are set in the call to InitLogin. That is called either during requireSession, or FB.Facebook.init. You can see the call in the Net tab of Firebug, by checking out the response to login_status.php.
What happens if you reverse the order of those calls? The waitUntilReady is basically setting up a callback, and then requireSession activates that callback. The cookies ought to be set before the next call to your server.
If it's still not working, you could try putting a breakpoint in the InitLogin function. Or, feel free to send me a link at lshepard at facebook and we can see what's up.
Offline
I'm calling FB.Facebook.init before this sequence happens. Can that cause a problem?
The user is initially not logged in when FB.Facebook.init is called, then they click on a link and I call FB.Connect.requireSession()... to get them logged in.
Because the documentation hasn't been fleshed out, it's very difficult to know what order things should be called.
Right now, I call this sequence when the page is loaded:
// See what Facebook thinks about whether we're logged in
FB.Connect.init();
FB.Connect.get_status().waitUntilReady( function( status ) {
;;;console.log( status );
switch ( status ) {
case FB.ConnectState.appNotAuthorized:
;;;console.log( 'Not authorized' );
mmfb.loggedIn = false;
FB.ApiClient.requireLogin( function( ex ) {
;;;console.log( 'exception: ', ex );
} );
break;
case FB.ConnectState.connected:
;;;console.log( 'Connected' );
mmfb.loggedIn = true;
break;
case FB.ConnectState.userNotLoggedIn:
;;;console.log( 'Not Logged in' );
mmfb.loggedIn = false;
}
} );
Then when the user indicates they want to log in, I call FB.Connect.requireSession().
Offline
Reversing the order didn't help. The fbsettings_.... cookie gets set, but not the other cookies.
If I don't do a reload right away, all the cookies get set. Something appears to be queued up that isn't able to be activated when I do an immediate reload().
Offline
I ended up writing a "waitForCookie" function that uses setTimeout to wait for the cookie to appear, then reload the page.
Offline
Make sure to wrap FB.Connect.get_status().waitUntilReady in FB.ensureInit(). See http://wiki.developers.facebook.com/ind … ct_Status.
Offline