Rails考拉“错误不支持的获取请求"经过长时间的任务-调用FB graph API [英] Rails koala "error unsupported get request" after long task - calling FB graph API

查看:84
本文介绍了Rails考拉“错误不支持的获取请求"经过长时间的任务-调用FB graph API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在完成了很长的任务(14秒后,与600个以上的Facebook通话可能会更多),我的应用返回了500个内部服务器错误,内容如下:

After a long task (14s and can be more with more than 600 call to Facebook) my app returns a 500 internal server error with the following description:

Koala::Facebook::APIError (GraphMethodException: Unsupported get request.) 

我所做的是这样的:

@FBGraph = Koala::Facebook::API.new
tud = MyUsers.all
tud.each do |user|

    graph = @FBGraph.get_object(user.fb_user_id)
    picture = @FBGraph.get_picture(user.fb_user_id)
    thisTud = MyUsers.find(user.id)
    thisTud.name = graph["name"]
    thisTud.url = graph["link"]
    thisTud.url_pic = picture

    if thisTud.save
        puts "Saved!"
    else
        puts "Error"
    end
end

我收到(在终端上)所有的"Saved!",但是在检索数据之后,它会自动执行mysql操作,并且失败.并且数据不会保存在数据库中.

I receive (on the terminal) all the "Saved!", but after retrieving the data, it does automatically the mysql operations and it fails. And the data is not saved on the DB.

中所建议这篇文章我将@FBGraph = Koala::Facebook::API.new放在了新的线程中,但是没有任何变化.

As suggested in this post I have placed the @FBGraph = Koala::Facebook::API.new in a new Thread, but nothing changes.

注意:当我用更少的用户执行相同的操作时,一切都很好.

Note: when I'd do the same operations with less users, all was working good.

推荐答案

hellvinz所说的是一个Facebook错误.

How hellvinz says is a facebook bug.

我现在找到了一种可行的解决方法:

I have find a workaround for now that seems that works:

更改此

graph = @FBGraph.get_object(user.fb_user_id)

对此

graph = @FBGraph.get_object("#{user.fb_user_id}?fields=id,name,username,picture,link")

明确声明这些字段似乎可以解决问题.

Explicitly declaring the fields seems that solve the problem.

如果这还不够的话,还有另外2种技巧可以解决问题:

And if this is not sufficient there are 2 more tricks that can resolve the problem:

  1. 在延迟(例如一个小时后)之后再次调用,并且仅调用未完成的请求
  2. 创建多个fb应用ID和帐户,以将请求与帐户区分开

这篇关于Rails考拉“错误不支持的获取请求"经过长时间的任务-调用FB graph API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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