Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Facebook回调附加'#_=_';返回URL_Facebook_Returnurl - Fatal编程技术网

Facebook回调附加'#_=_';返回URL

Facebook回调附加'#_=_';返回URL,facebook,returnurl,Facebook,Returnurl,Facebook回调已开始将#=\u哈希下划线添加到返回URL 有人知道为什么吗?解决方案是什么?不知道他们为什么这样做,但是,您可以通过重置页面顶部的哈希来解决这个问题: if(window.location.hash==“#u=quo”) window.location.hash=“”; Facebook使用一个框架,框架内的所有功能都使用AJAX通信。这种情况下最大的问题是保留当前页面状态。据我所知,Facebook决定使用模拟锚。这意味着如果你点击了某个地方,他们会在你的页面中模拟为一个

Facebook回调已开始将
#=\u
哈希下划线添加到返回URL


有人知道为什么吗?解决方案是什么?

不知道他们为什么这样做,但是,您可以通过重置页面顶部的哈希来解决这个问题:

if(window.location.hash==“#u=quo”)
window.location.hash=“”;

Facebook使用一个框架,框架内的所有功能都使用AJAX通信。这种情况下最大的问题是保留当前页面状态。据我所知,Facebook决定使用模拟锚。这意味着如果你点击了某个地方,他们会在你的页面中模拟为一个锚,当AJAX通信开始时,他们也会改变你URL的锚定位

当您尝试重新加载页面时(不输入,按F5),此解决方案通常会帮助您,因为您的浏览器会将带有锚定的整个URL发送到Facebook服务器。因此,Facebook会获取最新状态(你所看到的),然后你就可以从那里继续下去


当回调返回时带有
#u=
表示页面在离开之前处于基本状态。因为这个锚是由浏览器解析的,所以您不必担心它。

我看不出这个问题与FacebookAjax有什么关系。事实上,禁用JavaScript和纯粹基于重定向的登录也会出现此问题

与facebook的交流示例:

1。获取响应302找到位置:
2.获取响应302找到我的重定向URL?code=FB_code#
3.获取我的重定向URL?code=FB\u code\

对我来说,只有Firefox才会发生这种情况。

最近Facebook处理会话重定向的方式发生了变化。有关公告,请参阅本周博客文章中的“会话重定向行为的更改”。

通过:

会话重定向行为中的更改

本周,我们开始在 此字段留空。请确保您的应用程序能够处理此问题 行为

为了防止这种情况,请在登录url请求中设置重定向uri,如下所示:(使用Facebook php sdk)

$facebook->getLoginUrl(数组('redirect\u uri'=>$\u SERVER['SCRIPT\u uri'],'scope'=>'user\u about\u me');
更新

上面所说的正是解决这个问题的方法。然而,Facebook的文档化解决方案并不起作用。请考虑留下一个评论,然后得到更好的答案。在此之前,请在头标签上添加以下内容以解决此问题:


if(window.location.hash&&window.location.hash='#{
window.location.hash='';
}
或者更详细的选择(谢谢):


if(window.location.hash&&window.location.hash='#{
if(window.history&&history.pushState){
window.history.pushState(“”,document.title,window.location.pathname);
}否则{
//通过存储页面的当前滚动偏移量来防止滚动
变量滚动={
top:document.body.scrollTop,
左:document.body.scrollLeft
};
window.location.hash='';
//恢复滚动偏移,应无闪烁
document.body.scrollTop=scroll.top;
document.body.scrollLeft=scroll.left;
}
}

非常烦人,尤其是那些解析URI而不仅仅是读取$\u GET的应用程序。。。这是我编造的一个黑客。。。享受吧


//去掉URI中的Facebook剩余哈希
//必须在JS中完成,因为哈希仅存在于客户端
//IE和Chrome版本的黑客
if(字符串(window.location.hash).substring(0,1)=“#”){
window.location.hash=“”;
window.location.href=window.location.href.slice(0,-1);
}
//Firefox版本的黑客
if(String(location.hash).substring(0,1)=“#”){
location.hash=“”;
location.href=location.href.substring(0,location.href.length-3);
}
URI应该是干净的

如果要从url中删除剩余的“#”

$(窗口).on('load',函数(e){
if(window.location.hash='#u='){
window.location.hash='';//对于较旧的浏览器,在
history.pushState(“”,document.title,window.location.pathname);//整洁
e、 preventDefault();//无页面重新加载
}
})

将此添加到我的重定向页面修复了我的问题

if(window.location.href.indexOf('.#='.')>0){
window.location=window.location.href.replace(/#.*/,'');
}

您还可以在Facebook回调的
重定向uri
参数上指定自己的哈希值,这在某些情况下可能会有所帮助,例如
/api/account/callback#home
。如果您使用的是backbone.js或类似版本(不确定jquery mobile),当您被重定向回时,它将至少是一个与已知路由相对应的哈希;DR

if(window.location.hash==“#==quo”){
历史,国家
?history.replaceState(null,null,window.location.href.split(“#”)0])
:window.location.hash=“”;
}
带逐步说明的完整版本

//测试丑陋。
if(window.location.hash===“#==quo”){
//检查浏览器是否支持history.replaceState。
if(history.replaceState){
//将准确的URL保留到哈希。
var cleanHref=window.location.href.split(“#”)[0];
//替换地址栏中的URL,不要弄乱后退按钮。
replaceState(null,null,cleanHref);
}否则{
//好吧,您使用的是旧浏览器,我们可以去掉=u,但不能去掉#。
window.location.hash=“”;
}
}
逐步:Error: Invalid url "http://example.com/#_=_", missing hash prefix "#!".
window.location.hash = ''; // goes to /#, which is no better
window.location.hash = '!'; // goes to /#!, which allows Angular to take care of the rest
    app.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {

      // Make a trailing slash optional for all routes
      // - Note: You'll need to specify all urls with a trailing slash if you use this method.
      $urlRouterProvider.rule(function ($injector, $location) {
        /***
        Angular misbehaves when the URL contains a "#_=_" hash.

        From Facebook:
          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.

        Fix:
          http://stackoverflow.com/questions/7131909/facebook-callback-appends-to-return-url#answer-7297873
        ***/
        if ($location.hash() === '_=_'){
          $location.hash(null);
        }

        var path = $location.url();

        // check to see if the path already has a slash where it should be
        if (path[path.length - 1] === '/' || path.indexOf('/?') > -1) {
          return;
        }
        else if (path.indexOf('?') > -1) {
          $location.replace().path(path.replace('?', '/?'));
        }
        else {
          $location.replace().path(path + '/');
        }
      });

      // etc ...
    });
});
function redirect($url){
    echo "<script>window.location.href='{$url}?{$_SERVER["QUERY_STRING"]}'</script>";        
}
const appRoutes: Routes = [
  ...
  {path: '_', redirectTo: '/facebookLoginSuccess'},
  ...
]
export const routing = RouterModule.forRoot(appRoutes, { useHash: true });
return (req, res, next) => {
    console.log(req.originalUrl);
    next();
};
<script type="text/javascript">
    if (window.location.hash && window.location.hash == '#_=_') {
        window.location.href = window.location.href.split('#_=_')[0];
    }
</script>
 $loginURL = $helper->getLoginUrl($redirectURL, $fbPermissions);
 $loginURL = str_replace("#_=_", "", $loginURL);
 header("Location: " . $loginURL);
<script type="text/javascript">
 var idx=window.location.toString().indexOf("#_=_"); 
   if (idx > 0) { 
     window.location = window.location.toString().substring(0, idx); 
   } 
</script>
{
  path: '/_=_',
  redirect: '/', // <-- or other default route
},
if (window.location.hash === "#_=_"){
    history.replaceState 
        ? history.replaceState(null, null, window.location.href.split("#")[0])
        : window.location.hash = "";
}