2012-04-10 68 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登錄。