使用koala Ruby gem从Facebook上检索friends_history

时间:2012-07-09 15:00:07

标签: ruby-on-rails ruby ruby-on-rails-3 koala fb-graph

我想检索用户朋友education_history,我正在使用考拉宝石和红宝石。

我已添加了在omitaluth的initalizer文件中获取用户朋友education_history的权限::scope => 'user_education_history,friends_education_history

到目前为止,我可以获得用户朋友:name和:id,但不知道如何让用户朋友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

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

我通过使用考拉提供的字段密钥解决了我的问题,它更有效,工作更快:

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