Facebook自定义选项卡:我可以';t在子页面下获取FacebookSession


Facebook Custom Tab: i can't get FacebookSession under subpages

我想把我的网站(而不仅仅是一个特定的部分)集成到facebook选项卡下并检索用户信息,我成功地完成了。但问题是,当我浏览网站页面时,我无法获得用户信息。

例如,如果我使用:mysite.org/foo作为主页,在这里我可以毫无问题地获得所需的用户信息。但是当我导航到mysite.org/foo/bar时,session返回null。

   'Facebook'FacebookSession::setDefaultApplication(APP_KEY, APP_SECRET);
    $helper = new 'Facebook'FacebookCanvasLoginHelper();
    try {
        $session = $helper->getSession();
    } catch ('Facebook'FacebookRequestException $e) {
        echo "Exception occured, code: ".$e->getCode();
        echo " with message: ".$e->getMessage();
    } catch (Exception $e) {
        echo "Exception occured, code: ".$e->getCode();
        echo " with message: ".$e->getMessage();
    }

我正在使用javascript sdk来记录

window.fbAsyncInit = function() {
    FB.init({
      appId      : APP_KEY,
      xfbml      : true,
      version    : 'v2.1'
    });
    FB.getLoginStatus(function(response) {
        if (response.status === 'connected') {
          console.log('Logged in.');
        }
        else {
          console.log('Logging.');
          FB.login(function(response) {},{scope: 'email'});
        }
    });
  };

提前谢谢。

问题已解决:)

我必须用post-request替换网站中的所有链接,并在其中发送"signed_request"。

以下是可能需要改进的解决方案

<script type="text/javascript">
$(document).ready(function(){
    var $form = $('<form name="temp" method="POST"/>');
    $form.append('<input type="hidden" name="signed_request" value="<?=$_REQUEST['signed_request']; ?>" />');
    $form.appendTo($('body'));
    $('a').click(function(e){
        var href = $(this).attr('href');
        if(!isExternal(href)){
            e.preventDefault();
            $form.attr('action',href);
            $form.submit();
        }
    });
    function isExternal(url) {
       var match = url.match(/^([^:'/?#]+:)?(?:'/'/([^'/?#]*))?([^?#]+)?('?[^#]*)?(#.*)?/);
       if (typeof match[1] === "string" && match[1].length > 0 && match[1].toLowerCase() !== location.protocol) return true;
       if (typeof match[2] === "string" && match[2].length > 0 && match[2].replace(new RegExp(":("+{"http:":80,"https:":443}[location.protocol]+")?$"), "") !== location.host) return true;
      return false;
    }
});</script>