Attempting a client site authorization, and attempting to run within a canvas. If I access the my website directly http://mysite.com/ everything works. If I try to run via canvas https://apps.facebook.com/myapp it runs but getLoginStatus does not fire at all.
var curLoc = window.location;
FB.init({
appId: 'xxxxxxxxxxxxxxx', // App ID
channelUrl: curLoc.protocol + "//" + curLoc.hostname + ":" + curLoc.port + "/channel.html",
cookie: true, // enable cookies to allow the server to access the session
status: true,
oauth: true,
xfbml: true
});
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
smloader.gameVariables.smUserid = response.authResponse.userID;
facebook.isLoaded = true;
} else {
facebook.authUser();
}
}, true);
Login if needed.
function facebook.authUser() {
FB.login(function (response) {
if (response.authResponse) {
smloader.gameVariables.smUserid = response.authResponse.userID;
facebook.isLoaded = true;
}
else {
facebook.authUser();
}
}, { scope: 'email,publish_actions' });
}
Once Facebook.isLoaded is true, I know we are logged in and ready to continue. but it never gets there directly from the canvas page.
I am in sandbox mode, currently running via http not https as I don't
Any Ideas?
I have been facing the same pb and this is how i fixed it :
Even if the getLoginStatus() works within your http website, the getLoginStatus() will not fire at all within the fb canvas unless you provide a valid Secure Canvas URL (https://yoursite.com/) !
It means you need to run your app on a https server (port 443)
If you do not want to buy a certificate you can create and self-signed a certificate (see here : http://greengeckodesign.com/blog/2013/06/15/creating-an-ssl-certificate-for-node-dot-js/)
I Hope this will help
来源:https://stackoverflow.com/questions/12969633/getloginstatus-not-firing-with-calling-from-fb-canvas