Reputation: 2018
Probably a dumb thing to ask, but this will really help me get my head around FB integration.
I am using standard FB.init to use javascript SDK, and using PHP SDK to do some basic API calls:
FB.init({
appId : '265236093556723', // App ID
status : true, // check login status
// cookie : true, // enable cookies to allow the server to access the session. WHY IS THERE AN INFINITE LOOP WHEN THIS IS REMOVED?!?!?!?!?!
xfbml : true, // parse XFBML
oauth : true,
channelUrl : 'http://www.loveweber.co.uk/dev/fbchannel.php' // Channel File
});
I was testing stuff and commented out the cookie: true line. This caused the site to loop through realoding the page and im not sure why. I read everywhere that PHP uses this cookie set by Javascript... so is it something to do with the PHP call to the API?
Or maybe something to do with:
FB.Event.subscribe('auth.login', function(response) {
window.location.reload(); // When user logs in, the page refreshes...
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
the realoding of the page when a user logs in or out?
Thanks would help such a lot.
Upvotes: 0
Views: 501
Reputation: 31870
FB.Event.subscribe('auth.login', function(response) {
window.location.reload(); // When user logs in, the page refreshes...
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
I notice that your not checking the response variable in either event subscription. You should ensure that the response is what you think it is before you blindly do the reload(); The reason Facebook sends you the response object is because it is not always what you think.
The response object will be like:
{
status: "xxx", /* Current status of the session */
authResponse: { /* Information about the current session */
userID: "" /* String representing the current user's ID */
signedRequest: "", /* String with the current signedRequest */
expiresIn: "", /* UNIX time when the session expires */
accessToken: "", /* Access token of the user */
}
}
So be sure the response.status is 'connected' when you subscribe to auth.login. and then not 'connected' when you subscribe to the auth.logout.
Upvotes: 1