2012-07-09 37 views
0

我想檢索一個用戶朋友education_history,我正在使用考拉寶石和rubyonrails。使用考拉從Facebook檢索朋友education_history Ruby寶石

我有添加的權限用於獲取一個用戶的朋友education_history在我initalizer文件omniauth::scope => 'user_education_history,friends_education_history

到目前爲止,我可以得到用戶的朋友:名和:身份證,但不知道如何讓一個用戶朋友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 

任何想法?

回答

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