James Bradley
James Bradley

Reputation: 43

Facebook Open Graph Scraping

I've recently enabled the Facebook Open Graph stuff on my web app (so and so has just read this and that on here and there). Now I post the request to Facebook when a user posts something, as part of the page load in the controller. The problem is I receive the following error:

HTTP 500: Response body: {"error":{"type":"Exception","message":"Could not retrieve data from URL."}}

My first thought is that the open request to load the page is blocking any FB scraping of OG information, as it seems after it's been cached I no longer receive this error.

Is this likely? If so, what's the best way to work around it?

Upvotes: 2

Views: 1020

Answers (1)

WHY THIS HAPPENS: I had this same problem today, and it is because your Koala script (assuming you're using koala - if not, you should try it out because it's great) sends its request to Facebook before your URL is up. This means that when Facebook registers the post, it comes to the URL you specified to pick up the meta tags. Unfortunately, the page itself hasn't been loaded yet, giving it a 500 error

HOW TO SOLVE IT: Use the delayed_job gem to prevent your post call from occurring before the page loads, which allows facebook to scrape your metatags correctly.

FOR EXAMPLE:

def post_to_facebook([ACCESS_TOKEN])
  graph = Koala::Facebook::API.new([ACCESS TOKEN])
  graph.put_connections("me", "[APP NAMESPACE]:[ACTION]", :[OBJECT TYPE] => [OBJECT_URL])
end
handle_asynchronously :post_to_facebook

Upvotes: 3

Related Questions