2

I am trying to get a users friends checkins, I am using omniauth and koala 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!

  • Open your console and start with the ID field, specify another after verifying the first works. My initial assumption is that the checkins of friends is simply not available to you, but I'm not familiar enough with the API to be sure. – zkwentz Jan 02 '13 at 06:46
  • @DigitalMerc - I tried that before I posted this and I got the same error. And I have the right permissions. –  Jan 02 '13 at 14:29
  • At which field did it begin to happen? Or was it with the ID field itself? – zkwentz Jan 02 '13 at 16:02
  • @DigitalMerc - the checkins field –  Jan 02 '13 at 17:01

1 Answers1

0

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:

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

zkwentz
  • 1,095
  • 5
  • 22
  • 44