朋友签到与facebook图形api和rails - APIError



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

当一个用户被保存时,这个方法点击:

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

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

在字段中,你正在请求有关朋友的信息,但'checkins'不是个人资料字段,它是一个完全不同的连接。

你必须做的是循环遍历所有的好友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进行大量的调用。

最新更新