Facebook Open Graph from Rails Heroku

Facebook Open Graph from Rails Heroku

Solved it!

Really stupid actually. I had only one web dyno in my Heroku application. Since my only web dyno was doing the Facebook API call, there was no dyno to respond to the Facebook callback. You need at least 2 to get this to work.

The reason the code worked in heroku console was simply because the web dyno was not busy handling my request.

I might push that code to a work queue in the future as it seems more appropriate and let a worker dyno handle the Facebook publishing.

Publish open graph story in facebook using ruby (fb_graph)?

It's given in their wiki

# Publish an activity
action = me.og_action!(
app.og_action(:custom_action), # or simply "APP_NAMESPACE:ACTION" as String
:custom_object => 'http://samples.ogp.me/264755040233381'
)

https://github.com/nov/fb_graph/wiki/OpenGraph

Facebook doesn't see my opengraph meta tags

On your page, you have your Open Graph object type set to activity as shown below:

<meta property="og:type" content="activity" />

No Open Graph object schema exists for this type, which is likely the source of your problem. You can verify that here: http://graph.facebook.com/schema/og/activity.

Some common Open Graph object types have been pre-defined, and are documented at http://ogp.me/#types. Alternatively, you may define custom objects with custom attributes by creating a new object type of your choosing, and these should be namespaced in the form my_namespace:my_type.

I would recommend trying one of the predefined object types, such as website. Assuming that that fixes your problem, but you require more custom behavior, then move on to defining a custom, namespaced object type with custom fields of your choosing.

Submitting object to Facebook via open graph doesn't work, but then works after testing the URL in Facebook's object debugger?

I'm running into the same issue.

The only way I've been able to successfully publish actions for custom object types that I've defined is to manually test the object url with Object Debugger first, and then post the action on that object through my application.

Even using the linter API -- which Facebook suggests here -- gives me an error.

curl -X POST \
-F "id=my_custom_object_url" \
-F "scrape=true" \
"https://graph.facebook.com"

Only the debugger tool seems to actually scrape the page correctly.

Note that I didn't have this problem when using a pre-defined object type, such as "website":

<meta property="og:type" content="website" />

This problem only seems to affect custom object types for some reason.

UPDATE (WITH SOLUTION):

I finally figured this out. The problem actually arose from my application's inability to handle two simultaneous HTTP requests. (FYI: I'm using Heroku to deploy my Rails application.) When you make a request to the Facebook API to publish an action on an object URL (request #1), Facebook will immediately attempt to scrape the object URL you specified (request #2), and based on what it is able to scrape successfully, it returns a response to the original request. If I'm running request #1 synchronously, that will tie up my web process on Heroku, making it impossible for my application to handle request #2 at the same time. In other words, Facebook can't successfully access the object URL that it needs to scrape; instead, it returns some default values, including the object type "website". Interestingly, this occurred even when I fired up multiple web processes on Heroku. The application was intent on using the same web process to handle both requests.

I solved the problem by handling all Facebook API requests as background jobs (using delayed_job). On Heroku, this requires firing up at least one web process and one worker process. If you can do it, running API requests in the background is a good idea anyway since it doesn't tie up your website for users, making them wait several seconds before they can do anything.

By the way, I recommend running two background jobs. The first one should simply scrape the object URL by POSTing to:
https://graph.facebook.com?id={object_url}&scrape=true

Once the first job has completed successfully, fire up another background job to POST an action to the timeline:
https://graph.facebook.com/me/{app_namespace}:{action_name}?access_token={user_access_token}

MORE RECENT UPDATE:

Per the suggestion in the comments, using Unicorn will also do the trick without the need for delayed_job. See more here if you're using Heroku:

http://blog.railsonfire.com/2012/05/06/Unicorn-on-Heroku.html

Facebook login by omniauth on heroku is not working

You got redirection error because the image url will redirect user to another url. and there is a limitation in the open-uri when redirect http to https.

In the error message you can see this url: http://graph.facebook.com/102087018247/picture?type=large will be redirected to https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/13064_10202475740292_410664266178542_n.jpg?oh=ef118e9d947604c9c7055a92e2&oe=5A02F8B4

you can work around this issue by replacing http with https in your image url

"https://graph.facebook.com/#{auth.uid}/picture?type=large"

or using this way:

user.remote_image_url = auth.info.image.gsub(/\Ahttp:/, "https")

put_connections() to Facebook graph in Koala fails after a very long delay

Figured it out. Of course the debugger thing doesn't make sense. It worked because Facebook then has my view on their cache.

This is a classic reentrancy problem (which I can't believe I have to deal with in Rails!) -- Facebook's POST API is synchronous and it only returns after it calls back to my show controller. But since I only have 1 worker thread, there is no one servicing the request, thus the hang.

The fix is to invoke the API asynchronously in a thread.

Thread.new {
@fbgraph.put_connections("me", "myapp:view", :room => url_for(@room))
}


Related Topics



Leave a reply



Submit