getLoginStatus not firing with calling from FB canvas

て烟熏妆下的殇ゞ 提交于 2019-12-06 06:45:22

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!