Ruby on rails 无尾熊的Rails时间作业问题
我有以下由cron作业在特定时间执行的代码Ruby on rails 无尾熊的Rails时间作业问题,ruby-on-rails,facebook,oauth,koala,Ruby On Rails,Facebook,Oauth,Koala,我有以下由cron作业在特定时间执行的代码 @user.refresh_facebook_token @graph = Koala::Facebook::API.new(@user.oauth_token) @graph.put_connections("me", "feed", message: @post.content) logger.debug("Posted #{@post.content} at #{@post.buff
@user.refresh_facebook_token
@graph = Koala::Facebook::API.new(@user.oauth_token)
@graph.put_connections("me", "feed", message: @post.content)
logger.debug("Posted #{@post.content} at #{@post.buffer_time}")
这将调用用户模型中的以下代码:
def refresh_facebook_token
if facebook_token_expired?
# Get the new token
new_token = facebook_oauth.exchange_access_token_info(self.oauth_token)
Time.zone = self.time_zone
# Save the new token and its expiry over the old one
self.update_attribute(:oauth_token, new_token['access_token']);
self.update_attribute(:oauth_expires_at, Time.zone.now + new_token['expires'].to_i)
save
end
end
def facebook_token_expired?
Time.zone = self.time_zone
return Time.zone.now > self.oauth_expires_at
end
def facebook_oauth
@facebook_oauth ||= Koala::Facebook::OAuth.new(APP_ID, APP_SECRET)
end
我试图做的是在运行cron作业之前刷新facebook访问令牌(如果需要的话),这样我就可以写文章而不用担心过期的令牌。但是,我得到以下错误:
40050960 type: OAuthException, code: 190, error_subcode: 463, message: Error validating access token: Session has
expired on Mar 22, 2014 2:00am. The current time is Mar 22, 2014 8:50am. [HTTP 400]
根据(阅读场景3注释)我不能在cron作业中再次调用OAuth吗?有没有一种方法可以确保我能够在特定的时间发表文章,而不用担心过期的代币?我知道60天令牌也将过期,如果作业计划在未来61天内完成,我的应用程序可能仍需要刷新令牌。同样的问题,您找到解决方案了吗?嘿,SsouLlesS,在我写了这个问题之后,我最终调查了一下,发现尽管API声称已经淘汰了无限访问令牌,但我从API中夺回的“60天”令牌实际上是没有过期日期的令牌。我不知道他们是否更新了API以传回60天代币,但当我写这个问题时,情况并非如此。不幸的是,因为这意味着我不需要找到解决办法,我从来没有机会为我的问题想出一个好的解决方案:\