[英]Friends checkins with facebook graph api and rails - APIError
I am trying to get a users friends checkins, I am using omniauth and koala gem. 我正在尝试让用户朋友签到,我正在使用omniauth和考拉gem。
When a user gets saved this method hits: 保存用户后,此方法会命中:
def add_friends
friends_data = facebook.get_connections("me", "friends", :fields => "id, name, link, picture, gender, checkins")
friends_data.map do |h|
friend = Friend.new
friend.uid = h["id"]
friend.name = h["name"]
friend.image = h["picture"]
friend.gender = h["gender"]
friend.urls = h["link"]
friend.user_id = self.id
friend.save!
if (!h["checkins"].blank?)
checkin = Checkin.new
checkin.checkin_id = h["id"]
checkin.user_id = h["checkins"]["data"]["from"]["id"]
checkin.user_name = h["checkins"]["data"]["from"]["name"]
checkin.tags = h["checkins"]["tags"]["data"]["name"]
checkin.place_id = h["checkins"]["place"]["id"]
checkin.place_name = h["checkins"]["place"]["name"]
checkin.message = h["checkins"]["message"]
checkin.created_time = h["checkins"]["created_time"]
checkin.friend_id = friend.id
checkin.save!
end
end
end
But I get this error: 但是我得到这个错误:
Koala::Facebook::APIError: HTTP 500: Response body: {"error_code":1,"error_msg":"An unknown error occurred"}
I dont really know what that means, any ideas? 我真的不知道这意味着什么,有什么想法吗? And does anybody know how to define a limit on checkins with the koala gem?
有人知道如何用考拉宝石来确定登机限制吗? I tried something like this:
我尝试过这样的事情:
u.facebook.get_connections("me","friends", :fields => "checkins.limit(2)")
But I got the same error! 但是我遇到了同样的错误!
In fields, you're requesting information about a friend, but 'checkins' isn't a profile field, it's an entirely different connection altogether. 在字段中,您正在请求有关朋友的信息,但是“签到”不是个人资料字段,而是完全不同的连接。
What you must do is loop through all the friend IDs and get the checkins for each: 您需要做的是遍历所有朋友ID并获取每个的签到:
friend_checkins = []
friend_ids = u.facebook.get_connections("me","friends", :fields => "id")
friend_ids.each do |friend_id|
friend_checkins << u.facebook.get_connections(friend_id,"checkins")
end
Also, when doing this, it would be a great time to look into batch requests with Koala , as you could potentially be making a lot of calls to the API here.. 同样,在执行此操作时,这将是使用Koala查看批处理请求的好时机,因为您可能在这里对API进行了很多调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.