Facebook回调已经开始追加#_=_哈希下划线返回URL
有人知道为什么吗?解决方案是什么?
Facebook回调已经开始追加#_=_哈希下划线返回URL
有人知道为什么吗?解决方案是什么?
当前回答
使用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),因此不涉及路由匹配。
其他回答
对我来说,我让JavaScript重定向到另一个页面,以摆脱#_=_。下面的想法应该有用。:)
function redirect($url){
echo "<script>window.location.href='{$url}?{$_SERVER["QUERY_STRING"]}'</script>";
}
我看不出这个问题与facebook AJAX有什么关系。事实上,禁用JavaScript和完全基于重定向的登录也会出现这个问题。
一个与facebook交换的例子:
1. GET <https://www.facebook.com/dialog/oauth?client_id=MY_APP_ID&scope=email&redirect_uri=MY_REDIRECT_URL> RESPONSE 302 Found Location: <https://www.facebook.com/connect/uiserver.php?[...]>
2. GET <https://www.facebook.com/connect/uiserver.php?[...]> RESPONSE 302 Found MY_REDIRECT_URL?code=FB_CODE#_
3. GET MY_REDIRECT_URL?code=FB_CODE#_
我也只在火狐浏览器上遇到过这种情况。
删除“#_=_”(PHP)的最简单和干净的解决方案:
用“echo(”Location .php)代替“header("Location: xxx.php");"Href = 'xxx.php';");"
不知道他们为什么这样做,但是,你可以通过重置页面顶部的哈希来解决这个问题:
if (window.location.hash == "#_=_")
window.location.hash = "";
主要恼人的,特别是应用程序解析URI,而不只是读取$_GET…这是我拼凑出来的……享受吧!
<html xmlns:fb='http://www.facebook.com/2008/fbml'>
<head>
<script type="text/javascript">
// Get rid of the Facebook residue hash in the URI
// Must be done in JS cuz hash only exists client-side
// IE and Chrome version of the hack
if (String(window.location.hash).substring(0,1) == "#") {
window.location.hash = "";
window.location.href=window.location.href.slice(0, -1);
}
// Firefox version of the hack
if (String(location.hash).substring(0,1) == "#") {
location.hash = "";
location.href=location.href.substring(0,location.href.length-3);
}
</script>
</head>
<body>
URI should be clean
</body>
</html>