无法为 Facebook 评论设置管理员



我们的网站上有一个奇怪的问题,有Facebook评论。看起来Facebook抓取工具错误地解析了(至少一个)我们的网页,因此它不会接受管理员来审核评论。

如果您转到此链接:

http://www.beliefnet.com/Espanol/10-Atletas-olimpicos-mas-inspiradores.aspx

并查看源代码,您将看到我们在头部有适当的标签,包括一个用于 FB:Admin 的标签。如果我使用该帐户登录Facebook,则没有版主选项。

通过 facebook 对象调试器运行页面,我收到一个错误,指出我们的正文中有元标记。具体来说,此错误:

Meta Tags In Body:  You have tags ouside of your . This is either because 
your was malformed and they fell lower in the parse tree, or you accidentally
put your Open Graph tags in the wrong place. Either way you need to fix it 
before the tags are usable.

查看该页面底部抓取的URL,我看到Facebook似乎已经"重组"了我们的html,并将元标记从头部放入正文中。

有谁知道是什么原因造成的?我想也许我们在页面中的某个地方有一些格式错误的 html,它抛弃了所有内容,但我浏览了该页面的 html,它看起来不错。我在这里还缺少什么吗?

通过 validator.w3.org 运行您的 URL 会显示一些警告信号:

Line 77, Column 14: document type does not allow element "noscript" here; assuming missing "object" start-tag
Line 154, Column 699: document type does not allow element "meta" here

我能够将(潜在)问题缩小到您页面中的以下行:

document.write('<a href="' + OAS.config.url + 'click_nx.ads/' + OAS.config.sitepage + '/1' + OAS.config.rns + '@' + OAS.config.listpos + '!' + pos + '?' + OAS.config.query + '" target=' + OAS.config.target + '>');
document.write('<img src="' + OAS.config.url + 'adstream_nx.ads/' + OAS.config.sitepage + '/1' + OAS.config.rns + '@' + OAS.config.listpos + '!' + pos + '?' + OAS.config.query + '" border="0" /></a>');

这些 document.write() 行也未能通过 w3.org 验证器:

Line 53, Column 197: character "+" is not allowed in the value of attribute "target"

此外,我认为使用 document.write() 进行 DOM 插入是不好的(因为它会导致页面渲染阻塞)。您可以更改为使用 js 对象和 DOM 操作吗?

FB 获取您的 URL 后,它会通过 DOM 解析器运行它,当它遇到这些 document.write() 行时可能会窒息。事实上,这些行有一个跨越两个 document.writes() 的 元素可能会混淆解析器。解析器可能认为它已经到达页面的<正文>,因此出现"正文中的元标记"错误。

作为快速测试,请尝试将 fb:admins 元标记放在这些 document.write() 行上方。虽然,如果解析器仍然窒息,我不会感到惊讶,但值得一试。

为了测试页面的 html 源代码,我使用了此 php.net 页面末尾注释中提供的简单脚本:http://www.php.net/manual/en/class.domxpath.php

它产生了错误:

Unexpected end tag : a in /home/dlee/tmp/tmp.html, line: 54
Unexpected end tag : head in /home/dlee/tmp/tmp.html, line: 183
htmlParseStartTag: misplaced <body> tag in /home/dlee/tmp/tmp.html, line: 184

其中 tmp.html 是页面保存到文件中的 html。第 54 行是前面提到的 document.write() 行。

如果上述任何结果正在进行中,请告诉我,我将相应地编辑此答案。

所以最终的问题在于头部嵌套了一个<noscript>...</noscript>,它试图为未启用 JavaScript 的浏览器包含一个跟踪像素,作为我们使用的广告服务的一部分。

从Facebook提供给我们的"他们如何看到你的页面"的输出来看,这个问题应该很明显。 正文在脚本之后立即开始,但在标记开始之前。 显然,当Facebook解析器看到头部中应该在身体中的元素时,它会吓坏了,所以它会立即在那里启动身体。

。脸书输出...

        console.log(OAS);
    })();
</script><!-- End OAS Setup --><!-- Begin comScore Tag --><script>
      var _comscore = _comscore || [];
      _comscore.push({ c1: "2", c2: "8428430" });
      (function() {
        var s = document.createElement("script"), el = document.getElementsByTagName("script")[0]; s.async = true;
        s.src = (document.location.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js";
        el.parentNode.insertBefore(s, el);
      })();
    </script>
</head>
<body>
<noscript>
    </noscript>
    <!-- End comScore Tag -->

。我们的网页 ...

<head>   
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <asp:PlaceHolder id="OASHeader" runat="server" />
    <!-- Begin comScore Tag -->
    <script type="text/javascript">
      var _comscore = _comscore || [];
      _comscore.push({ c1: "2", c2: "8428430" });
      (function() {
        var s = document.createElement("script"), el = document.getElementsByTagName("script")[0]; s.async = true;
        s.src = (document.location.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js";
        el.parentNode.insertBefore(s, el);
      })();
    </script>    
    <!-- End comScore Tag -->
    <noscript>
        <img src="http://b.scorecardresearch.com/p?c1=2&c2=8428430&cv=2.0&cj=1" alt="" />
    </noscript>
    <script type="text/javascript">
    ....
    <body>
    ....

所以将来,无效的头部元素肯定会导致这个问题。

最新更新