Facebook开放图谱API - og:元标记被忽略

8
我正在解决一个问题,即页面标题和图片在Facebook点赞时没有被包括。经过使用OG调试器,看起来Facebook没有访问任何og:元标记。 这里是调试器的链接,它说正在推断页面上存在的og:urlog:title属性。
作为测试,我直接从开发者文档中的示例中复制了元标记和HTML模式,但仍然收到相同的警告。
以下是生成的HTML和头标签的开头:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>123-ABC Butterfly Fun Carpet 3'10" x 5'5" Rectangle</title>
<meta name="description" content="Transactiv Products" />
<meta name="title" content="Transactiv" />
<meta property="fb:app_id" content="289501899130" />
<meta property="og:site_name" content="Transactiv InRecv" />
<meta property="og:url" content="http://localhost:2609/Pages/ProductSummary.aspx?OrganizationProductID=617c54a0-189a-48af-9b5e-002148210208&StoreID=a1d6bc99-9a6a-4e46-bdb4-790be4e59bd4&ProductID=d6748a89-41f4-48aa-a1c1-5c28f87cc47f&PageName=MHMTest&PageID=236549899706529" />
<meta property="og:title" content="123-ABC Butterfly Fun Carpet 3'10" x 5'5" Rectangle" />
<meta property="og:type" content="website" />
<meta property="og:description" content="" />
<meta property="og:image" content="http://transactivazureprod.blob.core.windows.net/pictureblob/831a4d4a-dbe3-44f5-9ff8-12286cdc33f5" />

有任何想法吗?
4个回答

6

Facebook会读取您在此处输入的URL的所有属性: https://developers.facebook.com/tools/debug

Facebook将读取您指定的属性,但有时只有在所有4个属性都被指定(且不为空),而不仅仅是最后3个时才使用它们。

<meta property="og:url" content="YOUR_URL" />
<meta property="og:title" content="YOUR_TITLE" />
<meta property="og:description" content="YOUR_DESCRIPTION" />
<meta property="og:image" content="YOUR_IMAGE" />

5
明显的问题。标题没有正确结束。您在其中使用了"
我建议在echo之前执行str_replace('"', "''", $str)
也就是说, <meta property="og:title" content="123-ABC Butterfly Fun Carpet 3'10" x 5'5" Rectangle" /> 改为 <meta property="og:title" content="123-ABC Butterfly Fun Carpet 3'10'' x 5'5'' Rectangle" /> 编辑:
您还可以考虑执行htmlentities($str, ENT_QUOTES),如@TwoWholeWorms所建议的那样。

你说得完全正确 - 需要修复一些东西 - 然而,即使我没有遇到这个问题,Facebook 仍然忽略元标签 - 我也直接从开放图谱文档示例中提取了值,但它们仍然给我相同的警告: - SDG
你正在尝试使用 Linter 吗? - Robin Castlin
是的 - linter 告诉我它正在推断那些“required”属性,即使它们已经在页面上了。 - SDG
好的想法,但是同样的问题。 - SDG
1
最好使用htmlentities($str, ENT_QUOTES)而不是str_replace。有更多的字符会破坏解析器,而不仅仅是“。”。 - Benjamin Nolan
显示剩余3条评论

1

Facebook的爬虫在尝试访问您的网站时遇到了错误页面。

您可以通过调试页面底部的链接“查看我们的爬虫所看到的内容”来访问Facebook爬虫对您页面的视图。

另外,这似乎并不仅仅是与网页爬虫有关的问题,因为当我访问这个链接时,也会看到同样的消息:http://transactivstaging.cloudapp.net:8080/Pages/ProductSummary.aspx?OrganizationProductID=617c54a0-189a-48af-9b5e-002148210208&StoreID=a1d6bc99-9a6a-4e46-bdb4-790be4e59bd4&ProductID=d6748a89-41f4-48aa-a1c1-5c28f87cc47f&FBUserId=100002152993326&PageName=MHMTest&PageID=236549899706529&CurrentPage=0

ShoppingCart.GetShoppingCartItems.Failed If this Error persists, you can contact our support and provide the following Error Id as a reference

0

我猜想,除了Robin Castlin提到的标题值中的"(您也可以转义为&quot;),您的og:url中可能包含未转义的“&”符号。

如果您在og:url字段中用&amp;替换&,它是否能正常工作?

所以您需要替换为:

<meta property="og:title"
  content="123-ABC Butterfly Fun Carpet 3'10" x 5'5" Rectangle" />
<meta property="og:url"
  content="http://localhost:2609/Pages/ProductSummary.aspx?
  OrganizationProductID= ... &StoreID= ..." />

<meta property="og:title"
   content="123-ABC Butterfly Fun Carpet 3'10&quot; x 5'5&quot; Rectangle" />

<meta property="og:url"
  content="http://localhost:2609/Pages/ProductSummary.aspx?
  OrganizationProductID= ... &amp;StoreID= ..." />

确保元数据都包含有效的HTML。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接