Facebook Open Graph by Rails Heroku

I have been struggling with this problem all day, and I really need some input.

I have a Rails application (3.1.3) running on Heroku cedars, trying to post some Facebook Open Graph actions using gem fb_graph (2.4.0).

This is my code.

begin app = FbGraph::Application.new(ENV['facebook_app_id']) me = FbGraph::User.me(user.facebook_access_token) logger.info "Facebook: User #{user.name} reviewing game #{game_url(review.game)}" action = me.og_action!( app.og_action(:review), :game => game_url(review.game), :content => review.review, :rating => review.rating ) rescue Exception => exc logger.error "Failed to publish review #{review.id} to facebook #{user.facebook_auth}" logger.error "Facebook error msg: #{exc.message}" end 

If I go to the page of my application that tries to run this code, it will not be executed with the following message.

 FbGraph::InvalidRequest (Exception :: Could not retrieve data from URL.) 

But if I open the Heroku console, heroku run console and enter the code manually, it works fine.

My first thought was that game_url(review.game) where to blame, but after adding a log message I am sure that it will return the correct URL. And since all this works, when I launch it manually through the heroku console, it confirms that the URL should be accessible and deliver the requested data.

Any feedback or experience is appreciated.

+6
source share
3 answers

I decided!

Really stupid really. I had only one web diner in the Heroku app. Since my only web dyno made a Facebook API call, the dyno did not answer the Facebook callback. You need at least 2 to make this work.

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

In the future, I can push this code to the work queue, as it seems more appropriate and allows the worker to process the Facebook post dyno.

+11
source

An alternative to the second dinodator may be a Unicorn attempt - this will allow your application to serve the second call, and the first one will be blocked.

These articles provide some useful information on getting started with Unicorn:

+1
source

The following link seems to suggest that it is timeout related, although the actual solution has not yet been given. facebook "could not get data from url

You can also track responses for the above link.

0
source

Source: https://habr.com/ru/post/911763/


All Articles