Facebook 回调将“#_=_"附加到返回 URL [英] Facebook Callback appends '#_=_' to Return URL

查看:21
本文介绍了Facebook 回调将“#_=_"附加到返回 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Facebook callback has started appending #_=_ hash underscore to the Return URL

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

Does anyone know why? What is the solution?

推荐答案

通过 Facebook 的平台更新:

会话重定向行为的变化

本周,我们开始在redirect_uri中添加一个#____=____片段,当该字段留空.请确保您的应用程序可以处理此问题行为.

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,如下所示:(使用 Facebook php-sdk)

To prevent this, set the redirect_uri in your login url request like so: (using Facebook php-sdk)

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

更新

以上内容正是 文档 中所说的解决此问题的方法.但是,Facebook 的文档化解决方案不起作用.请考虑在 Facebook 平台更新博文 上发表评论并关注 这个错误 以获得更好的答案.在此之前,请将以下内容添加到您的 head 标记以解决此问题:

The above is exactly as the documentation says to fix this. However, Facebook's documented solution does not work. Please consider leaving a comment on the Facebook Platform Updates blog post and follow this bug to get a better answer. Until then, add the following to your head tag to resolve this issue:

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

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

Or a more detailed alternative (thanks 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆