Facebook打开图表从Rails Heroku [英] Facebook Open Graph from Rails Heroku

查看:119
本文介绍了Facebook打开图表从Rails Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一整天都在这个问题上,而且真的需要一些输入。



我有一个Rails应用程序(3.1.3)在Heroku Cedar上运行,尝试用gem fb_graph(2.4.0)发布一些Facebook Open Graph动作。



这是我的代码。

  begin 
app = FbGraph :: Application.new(ENV ['facebook_app_id'])
me = FbGraph :: User.me(user.facebook_access_token)

logger.infoFacebook:User#{user.name}审查游戏#{game_url(review.game)}

action = me.og_action!(
app.og_action(:review),
:game => game_url(review.game),
:content => review.review,
:rating => review.rating

rescue异常=>
logger.error无法将评论#{review.id}发布到脸书#{user.facebook_auth}
logger.errorFacebook错误msg:#{exc.message}
end

如果我去我的应用程序中尝试运行此代码的页面,它将失败并显示以下消息。

  FbGraph :: InvalidRequest(异常::无法从URL检索数据)

但是,如果我在哪里打开Heroku控制台, heroku运行控制台并且手工输入代码,它的工作完美。



我的第一个想法是 game_url(review.game)在哪里怪,但添加日志消息后,我确信它返回正确的URL。而且,当我通过英雄控制台手动运行时,整个事情都可以正常工作,它确认了可访问的URL并传送所请求的数据。



任何反馈或经验都是非常感谢。

解决方案

解决方案



我的Heroku应用程序中只有一个web dyno。由于我唯一的网页动画正在进行Facebook API调用,所以没有动力响应Facebook回调。您需要至少2次才能使其正常工作。



代码在heroku控制台中工作的原因仅仅是因为web dyno处理我的请求并不忙碌。 >

我可能会将该代码推送到未来的工作队列,因为它似乎更合适,让工作人员处理Facebook发布。


I've been fighting this problem all day, and could really need some input.

I have a Rails application (3.1.3) running on Heroku Cedar, trying to publish some Facebook Open Graph actions with 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 in my application that will try to run this code, it will fail with the following message.

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

But, if I where to open a Heroku console, heroku run console and type in the code by hand, it works perfectly.

My first thought was that game_url(review.game) where to blame, but after adding the log message, I'm sure that it returns the correct URL. And, since the whole thing works when I run it manually through heroku console it confirms that URL to be accessible and delivering the data requested.

Any feedback or experiences with this is greatly appreciated.

解决方案

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.

这篇关于Facebook打开图表从Rails Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆