Search code examples
phpfacebookwordpressfacebook-opengraphhttp-status-code-301

Facebook Open Graph Stories using backend server on Wordpress


I am currently trying to set up the ability to publish open graph stories for an app but I am running into trouble with facebook's scraper. *Note: I am replacing the values in the parenthesis with their correct values; the php is hosted on wpengine.

I have put the example php code (mydomian)/opengraph.php and when I enter (mydomian)/opengraph.php?fb:app_id=(my_id)&og:type=(type)&og:title=(title)&og:description=(descr)&og:image=(image)&body=(body) it generates the object as expected.

Unfortunately when I run it through the debugger I get:

Errors That Must Be Fixed Object Missing a Required Value: Object at URL '(mydomain).wpengine.com/opengraph.php' of type 'website' is invalid because a required property 'og:type' of type 'string' was not provided.

Redirect Path

original: (mydomian).wpengine.com/opengraph.php?fb:app_id=(my_id)&og:type=(type)&og:title=(title)&og:description=(descr)&og:image=(image)&body=(body) it generates the object as expected.

301: (mydomain).wpengine.com/opengraph.php //looks like it's redirecting and scraping this page instead

the end result of the scrape is

<!DOCTYPE html>
<html>
<head prefix="og: http://ogp.me/ns# product: http://ogp.me/ns/product#">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta property="fb:app_id" content="">
<meta property="og:url" content="(mydomain).wpengine.com/opengraph.php">
<meta property="og:type" content="">
<meta property="og:title" content="">
<meta property="og:image" content="">
<meta property="og:description" content="">
<title>Product Name</title>
</head>
<body>
          </body>
</html>

Like I said before when I visit this page via web browser myself the html contains the correct values, but for some reason the facebook scraper is getting just the base php with no input. Any ideas?


Solution

  • Decided to go around the problem and use our plugin to generate the meta properties per post instead. If anyone else comes across this issue, the code at http://www.wpbeginner.com/wp-themes/how-to-add-facebook-open-graph-meta-data-in-wordpress-themes/ seems to be working for our purposes. We generate a bunch of xml from custom post types for our app and that's what we needed to publish stories about.