FB.getLoginStatus不会触发回调函数 [英] FB.getLoginStatus does not fires callback function
问题描述
我正在建立一个页面选项卡应用程序,我想让粉丝rsvp的事件。所以我必须检查用户是否登录,如果不需要登录。这听起来很简单,但FB.getLoginStatus不会触发回调函数。这是代码摘录:
FB.init({
appId:window.appID,
status :true,
xfbml:true,
cookie:true,
oauth:true,
channelUrl:'http://example.com/fb/channel.html'
});
然后我简单地说 - 当然用户点击一个按钮 - 调用FB.getLoginStatus,但是它似乎没有做任何事情。
我已经检查了沙箱模式,FB.init成功,应用程序设置和开发环境中的URL。我可以调用FB.ui,虽然FB.ui使用方法:'oauth'我收到一条错误消息,说redirect_uri参数不能与next参数一起使用,这是不推荐使用的。这是非常奇怪的,因为我没有使用下一个参数。但是当我设置在未定义的旁边,它工作正常,我得到窗口,但它说应用程序配置不允许给定URL。可以期待,我可以登录,然后我有access_token。但是在新窗口中,getLoginStatus仍然不会执行任何操作。
所以欢迎任何建议。
谢谢,
Tamas
更新:
code> function onBodyLoad(){// on body onload
FB.init({
appId:window.appID,
status:true,
xfbml:true,
cookie:true,
oauth:true,
channelUrl:'http://example.com/fb/channel.html'
});
}
...
function getName(){// on button onclick
FB.getLoginStatus(function(response){
if(response.authResponse)
{
window.loggedIn = true;
debugString('Logged in');
} else
{
window.loggedIn = false;
debugString('not logged in');
}
},true);
if(window.loggedIn === undefined){
debugString('getLoginStatus does not exec'); //我总是得到这个消息
}
}
更新2 :我在一个不同的网址上创建了一个新的应用程序,它被配置为一个独立的网站。这些代码工作完美,我可以getLoginStatus,我可以登录等。在FB的上下文中和在使用FB JavaScript SDK的独立网站中有什么区别吗?
当您在与您注册的域不同的域上运行网站时,FB.getLoginStatus
不会触发回调该应用程序与。当我正在本地开发或在分段服务器上时,我通常会发现自己处于这种情况。
例如,如果您使用 example.com 注册该网站,而您的登台服务器是 example.mystagingserver.com ,回调不会发火。在这种情况下,您需要在Facebook中创建第二个应用程序,并将新应用程序的应用程序ID和密码用于。
I have a difficult problem. Difficult means I searched through the net and StackOverflow as well the whole FBJS SDK documentation and haven't find answer.
I am building a Page Tab application where I'd like to let fans to rsvp events. So I have to check if the user is logged in and if it doesn't I have to login. That sounds pretty easy, but FB.getLoginStatus doesn't fires callback function. This is the code excerpt:
FB.init({
appId: window.appID,
status: true,
xfbml: true,
cookie: true,
oauth: true,
channelUrl: 'http://example.com/fb/channel.html'
});
and then I simply - of course after the user clicks on a button - call FB.getLoginStatus, but it seems it doesn't do anything.
I've already checked sandbox mode, FB.init success, URLs in application settings and developing environment. I can call FB.ui, although FB.ui with method: 'oauth' I get an error message saying " The "redirect_uri" parameter cannot be used in conjunction with the "next" parameter, which is deprecated.". Which is very weird because I didn't used "next" parameter. But when I set next to undefined, it works fine, I get the window, but it says "Given URL is not allowed by the Application configuration.". Expect from that, I can login, then I've got the access_token. But in the new window, getLoginStatus still doesn't do anything.
So any advices are welcome.
Thanks, Tamas
UPDATE:
function onBodyLoad() { //on body onload
FB.init({
appId: window.appID,
status: true,
xfbml: true,
cookie: true,
oauth: true,
channelUrl: 'http://example.com/fb/channel.html'
});
}
...
function getName() { // on button onclick
FB.getLoginStatus(function(response){
if (response.authResponse)
{
window.loggedIn = true;
debugString('Logged in');
} else
{
window.loggedIn=false;
debugString('Not logged in');
}
}, true);
if (window.loggedIn === undefined) {
debugString('getLoginStatus did not exec'); // I always get this message
}
}
UPDATE 2: I created a new App on a different URL, which is configured as a standalone website. There these codes work perfectly, I can getLoginStatus, I can login, etc. Is there any difference working in the context of FB, and in a standalone website, using FB JavaScript SDK?
FB.getLoginStatus
does not fire the callback when you are running the website on a different domain than the one that you registered the app with. I usually find myself in this situation when I am developing locally or on a staging server.
For example, if you registered the site with example.com and your staging server is example.mystagingserver.com, the callback wont fire. In this case, you need to create a second application in Facebook and use the Application ID and Secret for the new app.
这篇关于FB.getLoginStatus不会触发回调函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!