2012-04-10 96 views
8

我有我的网页的HTML结构,如下所示。我已经添加了所有meta og标签,但Facebook仍然无法从我的网站上刮取任何信息。Facebook无法抓取我的网址

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"> 
    <head> 
      <meta http-equiv="Content-Type" content="text/html;" charset=utf-8"></meta> 
      <title>My Site</title> 
      <meta content="This is my title" property="og:title"> 
      <meta content="This is my description" property="og:description"> 
      <meta content="http://ia.media-imdb.com/images/rock.jpg" property="og:image"> 
      <meta content="<MYPAGEID>" property="fb:page_id"> 
      ....... 
    </head> 
    <body> 
    ..... 

当我输入了Facebook调试器URL(https://developers.facebook.com/tools/debug),我得到以下信息:

Scrape Information 
Response Code 404 

Critical Errors That Must Be Fixed 
Bad Response Code URL returned a bad HTTP response code. 


Errors that must be fixed 

Missing Required Property The 'og:url' property is required, but not present. 
Missing Required Property The 'og:type' property is required, but not present. 
Missing Required Property The 'og:title' property is required, but not present. 


Open Graph Warnings That Should Be Fixed 
Inferred Property The 'og:url' property should be explicitly provided, even if a value can be inferred from other tags. 
Inferred Property The 'og:title' property should be explicitly provided, even if a value can be inferred from other tags. 

为什么Facebook的不读元标签信息?页面可以被访问,而不是隐藏在背后的登录等

UPDATE

好吧,我也调试一下,这是我发现的。我在我的目录中设置了htaccess规则 - 我使用PHP Codeigniter框架并使用htaccess规则从url中删除index.php。

所以,当我没有index.php的Facebook调试器(https://developers.facebook.com/tools/debug)提供的URL,Facebook显示404,但是当我用index.php提供url时,它能够解析我的页面。

现在我该如何让facebook在Facebook没有index.php的时候抓取内容?

这是我的htaccess规则:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    #Removes access to the system folder by users. 
    #Additionally this will allow you to create a System.php controller, 
    #previously this would not have been possible. 
    #'system' can be replaced if you have renamed your system folder. 
    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    #When your application folder isn't in the system folder 
    #This snippet prevents user access to the application folder 
    #Submitted by: Fabdrol 
    #Rename 'application' to your applications folder name. 
    RewriteCond %{REQUEST_URI} ^application.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    #Checks to see if the user is attempting to access a valid file, 
    #such as an image or css document, if this isn't true it sends the 
    #request to index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    # If we don't have mod_rewrite installed, all 404's 
    # can be sent to index.php, and everything works as normal. 
    # Submitted by: ElliotHaughin 

    ErrorDocument 404 /index.php 
</IfModule> 
+0

这是报告404(未找到)错误代码。有**必须**你的网址喂你的东西有问题。 – 2012-04-10 21:28:05

+0

嗨克劳斯,我已经更新了我的问题,并进行了一些调试。请看看并让我知道您的意见 – Ninja 2012-04-11 07:02:02

回答

8

Facebook的文件包括在的Open Graph协议的细节以及如何将正确的meta标签,使Facebook能够准确地刮你的URL。

https://developers.facebook.com/docs/opengraphprotocol/

本质上讲,你会想要做的是包括一些特殊og:tags代替(或补充),以现有的meta标签。

<head> 
    <title>Ninja Site</title> 
    <meta property="og:title" content="The Ninja"/> 
    <meta property="og:type" content="movie"/> 
    <meta property="og:url" content="http://www.nin.ja"/> 
    <meta property="og:image" content="http://nin.ja/ninja.jpg"/> 
    <meta property="og:site_name" content="Ninja"/> 
    <meta property="fb:admins" content="USER_ID"/> 
    <meta property="og:description" 
      content="Superhuman or supernatural powers were often 
        associated with the ninja. Some legends include 
        flight, invisibility and shapeshifting..."/> 
    ... 
    </head> 

如果你有一个.htaccess文件重定向的东西,因此很难为Facebook刮你的网址,你也许能逃脱检测Facebook的履带与.htaccess和喂养它正确的标签。我认为,Facebook的履带提供用户代理是这样的:

facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php) 

的文件也有一节讲making sure that their crawlers can access your site

根据您的配置,您可以通过查看您的服务器access_log来测试。在运行apache的UNIX系统上,访问日志位于/var/log/httpd/access_log

所以,你可以在你的.htaccess文件使用类似下面的条目 -

RewriteCond %{HTTP_USER_AGENT} ^facebookexternalhit 
RewriteRule ^(.*)$ ogtags.php?$1 [L,QSA] 

[L,QSA]标志,我放在那里指出,这是将在当前强制执行的大号 AST规则请求(L)和QSA(查询字符串追加)指出,当URL被重写时,给定的任何查询字符串都将被传递。例如,URL,例如:

https://example.com/?id=foo&action=bar 

将传递给ogtags.php这样的 - ogtags.php?id=foo&action=bar。您的ogtags.php文件将根据传递的参数生成动态og:meta标签。

现在,只要您的.htaccess文件检测到Facebook用户代理,它就会通过他的ogtags.php文件(它可以包含正确的og:元信息)。请注意您在.htaccess中的任何其他规则,以及它们如何影响新规则。

从您详细介绍的.htaccess条目中,我建议将这个新的“Facebook规则”作为第一条规则。

+0

嗨Lix,非常感谢更新。我有一个问题,但在重写规则中,您提到我加载ogtags.html,但元标记将具有动态内容,基于请求的页面。我不能在那里给一个静态的HTML页面。我尝试用这个规则替换ogtags.html:RewriteRule ^(。*)$ index.php?/ $ 1 [L]但没有帮助。有关如何实现这一目标的任何想法? – Ninja 2012-04-11 07:46:43

+0

@Lix:你有什么想法,当我使用你的两个规则时,为什么我从facebook调试器工具中得到500错误?在此先感谢... – sergio 2013-07-29 18:33:06

+0

嘿那里@ser - 你检查你的服务器日志中的Facebook拒绝请求吗?我在这里添加了[这个链接](https://developers.facebook.com/docs/opengraph/howtos/maximizing-distribution-media-content/#crawl)到我的答案,这对你也许有用。 – Lix 2013-07-29 18:40:38

1

我有同样的问题,它是: 错误的响应代码:URL返回了错误的HTTP响应代码。

但奇怪这是解决它: 我添加

<meta property="og:locale" content="en_US" /> 

到我的网站HEAD标签和它的工作。

此外,不要忘记,在您的应用程序仪表板(您获得您的APP ID),您必须至少启用“启用Facebook登录的网站”并输入网站的URL。 否则无法使用......无论您是否在您的网站上使用任何Facebook登录。