Rails koala “error unsupported get request” after long task - calling FB graph API

本秂侑毒 提交于 2019-12-14 02:37:59

问题


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.) 

What I do is something like this:

@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

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.

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.


回答1:


How hellvinz says is a facebook bug.

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

change this

graph = @FBGraph.get_object(user.fb_user_id)

to this

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

Explicitly declaring the fields seems that solve the problem.

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

  1. Calling again after a time delay (for example after an hour), and calling only the requests incomplete
  2. Creating multiple fb app ID and accounts differentiating the requests with the accounts


来源:https://stackoverflow.com/questions/13729802/rails-koala-error-unsupported-get-request-after-long-task-calling-fb-graph-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!