Facebook回调已经开始追加#_=_哈希下划线返回URL
有人知道为什么吗?解决方案是什么?
Facebook回调已经开始追加#_=_哈希下划线返回URL
有人知道为什么吗?解决方案是什么?
当前回答
对我来说,我让JavaScript重定向到另一个页面,以摆脱#_=_。下面的想法应该有用。:)
function redirect($url){
echo "<script>window.location.href='{$url}?{$_SERVER["QUERY_STRING"]}'</script>";
}
其他回答
对于那些正在寻找简单答案的人 加上这个,对我很管用
if (window.location.hash === "#_=_"){
history.replaceState
? history.replaceState(null, null, window.location.href.split("#")[0])
: window.location.hash = "";
}
请查看Paul Schwarz的完整回答
https://stackoverflow.com/a/18305085/2694806
如果你使用vue-router,你可以添加到路由列表:
{
path: '/_=_',
redirect: '/', // <-- or other default route
},
通过Facebook平台更新:
更改会话重定向行为 本周,我们开始在redirect_uri中添加一个片段#____=____ 该字段为空。请确保您的应用程序可以处理这个问题 的行为。
为了防止这种情况,在你的登录url请求中设置redirect_uri(使用Facebook php-sdk)
$facebook->getLoginUrl(array('redirect_uri' => $_SERVER['SCRIPT_URI'],'scope' => 'user_about_me'));
更新
上述内容正是文档中所述的修复此问题的方法。然而,Facebook记录的解决方案并不奏效。请考虑在Facebook平台更新博客上留下评论,并关注这个错误以获得更好的答案。在此之前,将以下内容添加到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>
不知道他们为什么这样做,但是,你可以通过重置页面顶部的哈希来解决这个问题:
if (window.location.hash == "#_=_")
window.location.hash = "";
使用Angular 2 (RC5)和基于哈希的路由,我这样做:
const appRoutes: Routes = [
...
{path: '_', redirectTo: '/facebookLoginSuccess'},
...
]
and
export const routing = RouterModule.forRoot(appRoutes, { useHash: true });
据我所知,路由中的=字符被解释为可选路由参数定义的一部分(见https://angular.io/docs/ts/latest/guide/router.html#!#optional-route-parameters),因此不涉及路由匹配。