自从他们的平台更新以来,Facebook JavaScript SDK和PHP SDK没有像之前那样整合

时间:2012-12-06 18:34:04

标签: facebook facebook-javascript-sdk facebook-php-sdk facebook-login

由于Facebook昨天更新了developers roadmap changes,我的网站存在重大问题,因为它具有Facebook登录依赖性。

我认为问题是我在下面提供的Facebook JS SDK:

        <script type="text/javascript">
        (function(d, s, id) {
          var js, fjs = d.getElementsByTagName(s)[0];
          if (d.getElementById(id)) return;
          js = d.createElement(s); js.id = id;
          js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=ID";
          fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));

        var button;
        var userInfo;

        window.fbAsyncInit = function() {
            FB.init({ 
                appId: 'ID', //change the appId to your appId
                channelUrl : '//www.DOMAIN.com/channel.html', // Channel File
                status: true, 
                cookie: true,
                xfbml: true,
                oauth: true});

           showLoader(false);

           function updateButton(response) {
                button       =   document.getElementById('fb-auth');
                userInfo     =   document.getElementById('user-info');

                if (response.authResponse) {
                    //user is already logged in and connected
                    FB.api('/me', function(info) {
                        login(response, info);
                    });

                    button.onclick = function() {
                        FB.logout(function(response) {
                            logout(response);
                        });
                        $.post('scripts/logout.php',{ facebook_id:response.authResponse.userID } ,  function(data) {
                            //kill sessions
                        }); 
                  };
                } else {
                    //user is not connected to your app or logged out
                    button.innerHTML = '';
                    button.onclick = function() {
                        showLoader(false);
                        FB.login(function(response) {
                            if (response.authResponse) {
                                FB.api('/me', function(info) {
                                    login(response, info);
                              });   
                            } else {
                                //user cancelled login or did not grant authorization
                                showLoader(false);
                            }
                            window.location.href='/user/index.php';                             
                        }, {scope:'email,user_birthday,status_update,publish_stream,user_about_me'});   
                    }
                    FB.Event.subscribe('auth.authResponseChange', function(response) {
                      if (response.status === 'connected') {
                        window.top.location = '../user/index.php';
                      }
                    });
                }
            }

            // run once with current status and whenever the status changes
            FB.getLoginStatus(updateButton);
            //FB.Event.subscribe('auth.statusChange', updateButton);    
            // FB login insert/update               

            // Additional init code here
            FB.getLoginStatus(function(response) {
                if (response.status === 'connected') {
                    // connected
                    FB.api('/me', function(info) {
                            getLoginStatus(response, info);
                        });
                    if (response.authResponse.userID) {
                        $.post('scripts_profile/init.php',{ facebook_id:response.authResponse.userID } ,  function(data) {
                            //Good
                        });  
                    } else {
                        //Nothing   
                    }
                } else if (response.status === 'not_authorized') {
                    // not_authorized
                    login();
                } else {
                    // not_logged_in
                    login();
                }
            });             
        };
        // 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));

    </script>

我的网站还有Facebook PHP SDK,它与Facebook JS SDK集成。

自Facebook更新以来,JS SDK并没有像以前那样与PHP混合导致不一致。

例如,在我的网站上,如果用户被记录,则标题与访问者的标题不同。所以根据FB PHP SDK:

if (!my_profile) {
    //user header
} else {
    //visitor header
}

自更新以来,登录后,登录用户需要刷新页面以便按照自己的意愿查看...而不是简单地通过访问它。一旦我尝试直接访问该页面(通过点击链接或输入网址),它就会显示我已退出!

我花了最近10个小时来解决这个问题,我真的迷路了。非常感谢您的帮助!

提前谢谢大家。

1 个答案:

答案 0 :(得分:1)

我遇到了和你一样的问题,其他人也是如此。似乎是最新政策变化的错误。

见这里:http://developers.facebook.com/bugs/238039849657148