FB.Event.subscribe和登录按钮 [英] FB.Event.subscribe and login-button

查看:110
本文介绍了FB.Event.subscribe和登录按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的页面上,我有FB登录按钮代码。用户可以通过Facebook的授权加入我的网站,按FB登录按钮。我的网站让用户注销,其中许多人喜欢这样做。



在我授予我的FB帐户的网站后,退出我的网站,我无法登录,因为会话事件永远不会触发(除非我取消授权它)。我按FB登录按钮一个白页打开,然后立即关闭,没有任何反应。这似乎是因为FB会话没有改变(它已经存在),所以事件永远不会被触发。所以我想知道是否有办法除了隐藏FB的登录按钮,如果他们的会话存在自己的话。我尝试过auth.login,但也不会发射。



按钮:

 < fb:login-button perms =email,user_about_me,user_birthday>使用Facebook登录< / fb:login-button> 

事件:

 code> FB.Event.subscribe('auth.sessionChange',function(response){
document.location.href =/FacebookLogin.aspx;
});

重现步骤:


  1. 单击FB登录并授权应用程序(在本例中为我的网站)。用户被重定向到我的FB登录页面,并创建我的网站上的一个帐户。用户现在已登录到我的网站。


  2. 使用我的网站退出我的网站注销按钮


  3. 单击FB登录按钮重新登录到站点。这是用户应该从第1步重定向到同一页面,以便他们可以登录到该站点。


在步骤3中发生的一切都是一个白色的页面弹出几秒钟,然后关闭。该网站已经被授权,会话事件不被触发。



如果我使用一个浏览器进行授权,然后使用其他浏览器返回,也会发生这种情况。只要得到弹出窗口,它关闭,没有任何反应。我必须错过一些重要的事情。

解决方案

我有同样的问题,但过了一段时间,我解决了这个问题: / p>

  function after_login_button(){
FB.getLoginStatus(function(response){
if(response.status ==connected){
//用户登录!在这里执行你的代码
}
},true);
}

您还需要在登录按钮上调用onlogin事件: p>

 < fb:login-button onlogin =after_login_button()perms =email,user_about_me,user_birthday> ; / FB:登录按钮> 

这适用于我=)。



PS - 顺便说一下,我使用的是OAuth 2.0,你也应该将你的应用迁移到它,因为在开发者区域,他们说:
请记住,所有应用必须在10月1日之前迁移到OAuth 2.0。



对不起,最终的英语错误= S


On my page I have the FB login button code. A user is able to join my site by authorizing it with Facebook, by pressing the FB login button. My site lets users log out and many of them like to do that.

After I authorize my FB account for the site, log out of my site, I can't login any more because the session event never fires (unless I de-authorize it). I press the FB Login button a white page opens, then closes right away, and nothing happens. This seems to be because the FB session doesn't change (it already existed) so the event is never fired. So I'm wondering if there's a way around this aside from hiding FB's login button and making my own if their session exists. I tried "auth.login" but that doesn't fire either.

Button:

<fb:login-button perms="email,user_about_me,user_birthday">Login with Facebook</fb:login-button>

Event:

 FB.Event.subscribe('auth.sessionChange', function (response) {
                        document.location.href = "/FacebookLogin.aspx";
                    });

Steps to reproduce:

  1. Click FB login and authorize app (in this case my site). User is redirected to my FB login page and an account on my site is created. The user is now logged into my site.

  2. Logout of my site using my sites logout button

  3. Click the FB login button to log back into site. This is where the user should be redirected back to that same page from step 1 so they can be logged into the site.

All that happens in step 3 is a white page pops up for a couple seconds and then closes. The site is already authorized and the session event isn't fired.

This also happens if I authorize with one browser and then go back with a different browser. Just get the popup, it closes and nothing happens. I must be missing something important.

解决方案

I had the same problem but, after a while, i solved it doing this:

function after_login_button(){
    FB.getLoginStatus(function(response) {
        if (response.status=="connected") {
            //User logged in! Do your code here
        }
    }, true);
}

You also need to call the onlogin event on the login-button:

<fb:login-button onlogin="after_login_button()" perms="email,user_about_me,user_birthday">Login with Facebook</fb:login-button>

This worked for me =).

PS - By the way, I'm using OAuth 2.0 and you should migrate your application to it too because in the developers zone, they say: "Remember that all apps must migrate to OAuth 2.0 by October 1".

Sorry for eventual english errors =S

这篇关于FB.Event.subscribe和登录按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆