开发者

Facebook Login button does not trigger page refresh, FB.Event.subscribe doesn't seem to be registering

开发者 https://www.devze.com 2023-04-11 01:11 出处:网络
I have Login with Facebook on my site. I\'m using the JS-SDK, coupled with the PHP-SDK. I\'m 99.9% sure I have all the correct files in the correct places, as the actual login works. However, I canno

I have Login with Facebook on my site. I'm using the JS-SDK, coupled with the PHP-SDK.

I'm 99.9% sure I have all the correct files in the correct places, as the actual login works. However, I cannot get the page to fire a reload once the user has been logged in.

This is the facebook login button code ('Scope' is the new 'perms', as I just found out today):

<fb:login-button scope="email,user_birthday">Sign In</fb:login-button>

Once the user authorizes, etc, the Dialog closes, but then nothing happens. The user isn't logged in yet, and the page does not reload.

When I manually reload, the user is logged in.

This is the code I have in my footer that should listen for the login:

<script>
    FB.Event.subscribe('auth.login', function(response) {
        window.location.reload();
    });
</script>

In my Chrome developer tools JS console, I get an error saying "Uncaught Reference: FB is not define开发者_JAVA技巧d". This error is there as soon as the page loads, even before the Facebook Login button is clicked.

Any ideas as to what I might be doing wrong? Thanks!


I've found that passing the application secret to the auth.login call causes the event to fire correctly. You can pass the application secret from PHP to the javascript function, like this:

<script>
    FB.Event.subscribe('auth.login', function(response) {
        window.location.reload();
    }, secret: '<?php print $facebook->getApiSecret(); ?>');
</script>

This has since been fixed by Facebook.

0

精彩评论

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

关注公众号