Search code examples
ruby-on-railsrubyruby-on-rails-3koalafb-graph

Retrieve friends education_history from Facebook using koala Ruby gem


I would like to retrieve a users friend education_history, I am using koala gem and rubyonrails.

I have add the permission for getting a users friend education_history in my initalizer file for omniauth: :scope => 'user_education_history,friends_education_history

So far I can get the user friend :name and :id, but have no idea how to get a users friends education_history.

def add_friends
    facebook.get_connections("me", "friends").each do |hash|
      self.friends.where(:name => hash['name'], :uid => hash['id']).first_or_create
    end
end

Any ideas?


Solution

  • I solved my problem by using a fields key provide by koala, it more efficient and works fast:

    def add_friends
        facebook.get_connections("me", "friends", :fields => "name, id, education").each do |hash|
          self.friends.where(:name => hash['name'], :uid => hash['id'], :highschool_name => hash['education'][0]['school']['name'], :graduateschool_name => hash['education'][1]['school']['name']).first_or_create
        end
      end