问题
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:
- Calling again after a time delay (for example after an hour), and calling only the requests incomplete
- 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