登录/退出按钮不再保持状态

时间:2012-07-04 17:34:29

标签: iframe facebook-javascript-sdk facebook-social-plugins facebook-login

我的代码工作正常,直到过去24小时。我没有改变任何东西,但现在#fb按钮更小了,它不再说"退出"什么时候应该。

您可以在Homewrd处看到这一点。

以下代码嵌套在BODY> ROOT:

<div id="fb-root"></div>
<script type="text/javascript">
    // Load the SDK Asynchronously
    (function(d){
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) {return;}
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    }(document));

    // Init the SDK upon load
    window.fbAsyncInit = function() {
        FB.init({
            appId:'271193286279763',
            channelUrl:'//'+window.location.hostname+'/channel',
            status:true,
            cookie:true,
            xfbml:true
        });

        // Conditional UI for landing page
        if (landing) {
            FB.getLoginStatus(function(response) {                                                                                                                              
                if(response && response.status == 'connected') {                                                                                                                
                    FB.api('/me', function(response) {
                        var heading = $('#goods h1').text().replace('Homewrd','Welcome '+response.first_name+'!');
                        $('#goods h1').text(heading);
                    });
                }
            });
        }

        // listen for and handle auth.statusChange events
        FB.Event.subscribe('auth.statusChange', function(response) {
            fbEventful = true;
            if (response.authResponse) {
                fbToken = response.authResponse.accessToken;
                $('#fb-button').css({'display':'inline','float':'left'});
                $('#toolbox').css({'display':'inline'});
                $('#local-login').hide();
                $('#local-logout').hide();
                currentUser = {
                    fbid:response.authResponse.userID
                }
                displayPicture();
            } else {
                $.cookie('cuat', null);
                $.ajax({
                    url:'/logout.json',
                    type:'delete',
                    success:function() {
                        ajaxOff();
                        renderLocal();
                    }
                });
            }
        });

        FB.Event.subscribe('auth.login',
            function(response) {
                FB.api('/me', function(me){
                  if (me.name) {
                    currentUser = {
                        fbid:me.id,
                        email:me.email,
                        first_name:me.first_name,
                        last_name:me.last_name
                    }
                    params = {
                        fbid: currentUser.fbid,
                        user: {
                            fbid:currentUser.fbid,
                            email:currentUser.email,
                            first_name:currentUser.first_name,
                            last_name:currentUser.last_name
                        }
                    }
                    $.ajax({
                        url:domain+'/user.json',
                        data:params,
                        dataType:'json',
                        type:'post',
                        success:function(e) {
                            cuat = e.user.auth_token;
                            $.cookie('cuat', cuat, {
                                path:'/',
                                expires:7
                                }
                            );
                            if (rurl) {
                                refreshSession();
                            }
                            if (storedProcedure!==null) {
                                storedProcedure();
                            }
                        }
                    });
                  }
                });
            }
        );

        $('#local-logout a').click(function(e) {
            e.preventDefault();
            var x = confirm('Are you sure that you want to logout?');
            if (x===true) {
                ajaxOn();
                $.ajax({
                    url:'/logout.json',
                    type:'delete',
                    success:function() {
                        ajaxOff();
                        window.location.reload();
                    }
                });
            }
            return false;
        });

        setTimeout(function() {
            if (!fbEventful) {
                renderLocal();
            }
        },1000);
    }
</script>
<div id="header">
    <div id="logo">
        <h1>Logo Link</h1>
    </div>
    <div id="session">
        <div id="fb-button" autologoutlink="true" class="fb-login-button" scope="publish_stream,email,user_about_me,user_birthday,user_hometown,offline_access"></div>
        <div id="fb-picture"></div>
        <div id="local-login"><p>local login link</p></div>
        <div id="local-logout"><p>local logout link</p></div>
    </div>
</div>

0 个答案:

没有答案