繁体   English   中英

使用Facebook图形API和Rails的朋友签到-APIError

[英]Friends checkins with facebook graph api and rails - APIError

我正在尝试让用户朋友签到,我正在使用omniauth和考拉gem。

保存用户后,此方法会命中:

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

但是我得到这个错误:

Koala::Facebook::APIError: HTTP 500: Response body: {"error_code":1,"error_msg":"An unknown error occurred"}

我真的不知道这意味着什么,有什么想法吗? 有人知道如何用考拉宝石来确定登机限制吗? 我尝试过这样的事情:

u.facebook.get_connections("me","friends", :fields => "checkins.limit(2)")

但是我遇到了同样的错误!

在字段中,您正在请求有关朋友的信息,但是“签到”不是个人资料字段,而是完全不同的连接。

您需要做的是遍历所有朋友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

同样,在执行此操作时,这将是使用Koala查看批处理请求的好时机,因为您可能在这里对API进行了很多调用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM