简体   繁体   English

使用koala Ruby gem从Facebook上检索friends_history

[英]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. 我想找一个用户朋友education_history,我正在使用考拉宝石和红宝石。

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 我已经在omitaluth的initalizer文件中添加了获取用户朋友education_history的权限: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. 到目前为止,我可以得到用户朋友: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

Any ideas? 有任何想法吗?

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

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

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