8

以下に示すように、ページの HTML 構造があります。すべての meta og タグを追加しましたが、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 デバッガー (https://developers.facebook.com/tools/debug) に URL を入力すると、次のメッセージが表示されます。

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 がメタ タグ情報を読み取らないのはなぜですか? ページはアクセス可能で、ログインなどの背後に隠れていません。

アップデート

さて、私は少しデバッグを行いました。これが私が見つけたものです。ディレクトリに htaccess ルールを設定しています。PHP Codeigniter フレームワークを使用しており、url から index.php を削除するための htaccess ルールがあります。

したがって、index.php なしで facebook デバッガー (https://developers.facebook.com/tools/debug) に URL をフィードすると、facebook は 404 を表示しますが、index.php を含む URL をフィードすると、解析できます。マイページ。

URLにindex.phpがない場合、Facebookのスクレイプコンテンツを作成するにはどうすればよいですか?

これは私の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>
4

2 に答える 2

10

Facebook のドキュメントには、Open Graph プロトコルの詳細と、Facebook が URL を正確にスクレイピングできるように正しいメタ タグを含める方法が含まれています。

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

基本的にやりたいことはog:tags、既存のメタ タグの代わりに (または追加で) 特別なものを含めることです。

  <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 が URL をスクレイピングするのを困難にしている場合、Facebook のクローラーを検出し.htaccessて正しいタグをフィードすることで回避できる可能性があります。Facebook クローラーが提供するユーザー エージェントは次のとおりだと思います。

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

ドキュメントには、クローラーがサイトにアクセスできることを確認することについて説明しているセクションもあります。

構成によっては、サーバーの access_log を調べてこれをテストできます。apache を実行している UNIX システムでは、アクセス ログは にあります/var/log/httpd/access_log

したがって、ファイルでこれに似たエントリを使用でき.htaccessます-

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

そこに配置した[L,QSA]フラグは、これが現在のリクエストに適用される最後のルールであることを示し ( )、 (Query String Append) は、指定されたクエリ文字列が URL の書き換え時に渡されることを示しています。たとえば、次のような URL です。LQSA

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

このように渡されogtags.phpます - ogtags.php?id=foo&action=bar。ファイルogtags.phpは、渡されたパラメーターに従って動的な og:meta タグを生成するために提供されます。

これで、ファイルが Facebook ユーザー エージェントを検出するたびに、ファイル (正しい og:meta 情報を含むことができます).htaccessが彼に渡されます。ogtags.phpあなたが持っている他のルール.htaccessと、それらが新しいルールにどのように影響するかを知っておいてください.

あなたが詳述したエントリから、.htaccessこの新しい「Facebook ルール」を最初のルールとして配置することをお勧めします。

于 2012-04-10T21:32:00.650 に答える
1

私は同じ問題を抱えていました: 悪い応答コード: URL が悪い HTTP 応答コードを返しました。

しかし、奇妙なことに、これがそれを解決したものです:私は追加しました

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

私のサイトのHEADタグに追加するとうまくいきました。

また、アプリケーション ダッシュボード (APP ID を取得する場所) で、少なくとも「Facebook ログインのある Web サイト」を有効にして、Web サイトの URL を入力する必要があります。そうしないと、サイトで Facebook ログインを使用していなくても機能しません。

于 2012-12-31T08:31:08.093 に答える