开发者

FB Login button not calling onlogin function

I have my fb login button created as so

<fb:login-button perms="email" size="small" onlogin="check_login_session()">Sign Up Using Facebook</fb:login-button>

I have also defined the check_login_session function already as I'm using it on a .click link elsewhere on the page(which does work). However, my problem is when I'm already logged in to FB and I click the button, the FB popup appears, then dissapears and it does nothing. The onlogin is not called nor is any error displayed.

If I was to logout however, and then click the button, it would give me the fb login prompt, and after filled out and submitted would behave as it is supposed to. It's only when I'm already logged in and I click the FB login button that the issue occurs. Any Ideas?

Edit: I found that it does cal开发者_C百科l it if I say put alert("Test") in the onlogin but any function I define on the page and try to call it returns saying it's not defined.


I think you want to be notified about a logged in user either after a login happened or of a user comes to teh page and is already logged in. In this case you have to subscribe to the auth event and handle it:

FB.Event.subscribe('auth.authResponseChange', function(response) { if (response.status === 'connected') { //yourcode } else if (response.status === 'not_authorized') { //your code } else { //yourcode } });


The new facebook login flow says to only display the facebook login button if the user is not currently logged into facebook. If you display it anyway, nothing will happen when they click on it because it will detect that the user is already logged into facebook and so will exit the login process and the post login hook won't be called. The facebook documentation says to first detect whether the user is already logged into facebook, and if they are logged in, grab the facebook uid and simply execute the function you would have called as part of the post login hook. The facebook login button is simply that--a button to log into facebook and not a button to log into your site.


The event says onlogin, so it will only execute when you login through Facebook Connect.

If you are already logged in on Facebook Connect, then the function won't execute because you're already logged in...?


Most likely the function you're trying to call isn't accessible on that page even though you think it should be. Make sure you removed the () after the function's name. The fact that "alert" does work but your function doesn't kind of proves that. Make sure your function can be accessed by the script by making it global and ensuring your script is loaded.


The function has to be defined on the window. The solution is:

// somewhere before the button is rendered
window.loginCallback = () => {
    // callback logic
}

    <div
      className="fb-login-button"
      data-max-rows="1"
      data-size="large"
      data-button-type="continue_with"
      data-onlogin="loginCallback();"
    ></div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜