3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

facebookOGPの設定方法とキャッシュに苦しめられた点

Last updated at Posted at 2015-04-09

手順

  1. こちらのMyApp -> Add new AppよりfbIdを発行
  2. こちらを参考に必要な情報を入力してup
  3. こちらにチェックしたいURLを入れて確認
  4. 基本3で出たエラーを無くすように進めれば問題ない

ハマった点

  • 画像の大きさは200×200以上でないと別の画像が使われる
  • urlは末尾にスラッシュ/がいる
  • canonicalとurlの指定は無しにするか、表示しているページを指す
  • 画像の背景が透過されているとスマホのとき背景が黒くなる

特にハマった点

問題点:facebookシェアするときに画像が出ない、別の画像が出る

OGPが完璧に設定出来ていない状態でクロールされちゃうと
そっちのURLがキャッシュにたまってしまい
OGP設定を完成させてもキャッシュクリアしないと反映されなくなる

解決策:以下「URL」にキャッシュクリアしたいurlを入れてhttpアクセス

https://graph.facebook.com/?scrape=true&id=UR

とのこと

ということは例えば

キャッシュクリアしたいURLが
http://example.com/:id
の場合、以下のように自動生成してあげれば解決出来そう

http.rb
require 'open-uri'
  for i in 1..2000 do
    cache_url = 'https://graph.facebook.com/?scrape=true&id=http://example.com'+i.to_s
    open(cache_url) do |f|
    print f.read
  end
end

根本の解決策

当たり前だが、初めて公開するときに完璧な設定出来るようにすること...
テストサーバーでbasic認証やIP制限をかけていても
こちらに書かれている方法でチェックは出来るので

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?