Facebook回调将’#_ = _’添加到返回URL

Facebook回调已开始将#_ = _哈希下划线附加到返回URL

有人知道为什么吗?解决办法是什么?

最佳答案
通过Facebook’s Platform Updates

Change in Session Redirect Behavior

This week, we started adding a fragment #_=_ to the redirect_uri when
this field is left blank. Please ensure that your app can handle this
behavior.

为了防止这种情况,在您的登录url请求中设置redirect_uri,如下所示:(using Facebook php-sdk)

$facebook->getLoginUrl(array('redirect_uri' => $_SERVER['SCRIPT_URI'],'scope' => 'user_about_me'));

更新

上面正是070​​01说要解决这个问题。然而,Facebook的文档解决方案不工作。请考虑在Facebook Platform Updates blog post留下评论,并按照this bug得到更好的答案。在此之前,请将以下内容添加到head标记中,以解决此问题:

<script type="text/javascript">
    if (window.location.hash && window.location.hash == '#_=_') {
        window.location.hash = '';
    }
</script>

或更详细的替代(感谢niftylettuce):

<script type="text/javascript">
    if (window.location.hash && window.location.hash == '#_=_') {
        if (window.history && history.pushState) {
            window.history.pushState("", document.title, window.location.pathname);
        } else {
            // Prevent scrolling by storing the page's current scroll offset
            var scroll = {
                top: document.body.scrollTop,
                left: document.body.scrollLeft
            };
            window.location.hash = '';
            // Restore the scroll offset, should be flicker free
            document.body.scrollTop = scroll.top;
            document.body.scrollLeft = scroll.left;
        }
    }
</script>

转载注明原文:Facebook回调将’#_ = _’添加到返回URL - 代码日志