Search code examples
ruby-on-railsfacebookfacebook-graph-apimeta-tags

Open Graph meta tags not accessible, preview of page in Facebook shows "422"?


I can't make my open graph tags accessible to Facebook. When I try to share a page, the site links properly, but the og attributes don't show up, and the title just displays as "422". I'm not sure what this means.

When I run the facebook debugger https://developers.facebook.com/tools/debug/og/object/ I get the following error, which isn't very helpful:

Error parsing input URL, no data was cached, or no data was scraped.

Using the echo feature in the debug tools, all I get is:

Document returned no data

The meta tags appear to be set up properly in my document:

<!DOCTYPE html>
<html>
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#">
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="robots" content="noarchive,noodp,noydir" />
  <meta name="referrer" content="always" />
  <meta property="fb:app_id" content="375576830972731" />
  <meta property="og:site_name" content="Site Name" />
  <meta property="og:title" content="Title of content" />
  <meta property="og:url" content="https://website.domain.com/123456" />
  <meta property="og:image" content="http://s3-us-west-1.amazonaws.com/domain/media/images/001/original/001" />
  <meta property="og:description" content="Description of content" />
  <meta property="og:type" content="article" />
</head>

I made sure to allow for the Facebook crawlers in robots.txt:

User-agent: Facebot
Allow: /

User-agent: facebookexternalhit/1.1
Allow: /

What I am I missing?


Solution

  • The problem here was my protect_from_forgerymethod in application.rb. I added an exception and the Facebot can now see the page.

    class StoriesController < ApplicationController    
      protect_from_forgery except: :show