Facebook session always null after page refresh - javascript
I am using javascript in my webpage to retrieve the session for a user who has already approved my app and who is connected to Facebook. However, when I refresh the page after logging into Facebook the session is never开发者_如何学JAVA retrieved and is always null... I can't understand why.
here is my javascript for facebook connect:
window.fbAsyncInit = function() {
FB.init({
appId : 'MY APP ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.getLoginStatus(function(response) {
if (response.session) {
showLogout();
} else {
showLogin();
}
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
FB.Event.subscribe('auth.login', function() {
showLogout();
});
//when a user hits login it calls this function which works fine.
function loginfuncfb() {
FB.login(function(response) {
if (response.session) {
if (response.perms) {
showLogout();
} else {
showLogin();
}
} else {n
showLogin();
}
}, {perms:'email,publish_stream,offline_access'});
}
Please help. Thanks
*EDIT
I just want to let out some frustration here and tell you all that I have never in my life worked with such a problematic set of developer tools/SDKs as that of Facebook and I have never found it so difficult to get answers regarding technical difficulties. There are hardly any real solutions posted regarding facebook issues, the Facebook documentation is pathetic, and worst of all the terminology used in referring to facebook functions etc is really vague. I can't believe how long i've been stuck on this stupid petty problem...
Well after doing everything under the sun to figure this out, it turned out to be the fact that I my accepting 3rd party cookies in firefox was the disabled.
Just a wild guess without looking at any documentation, maybe the order you are doing things is wrong --- it seems like
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
Should be done before anything else.
精彩评论