【发布时间】:2011-08-17 20:42:45
【问题描述】:
我的会话控制器中有以下代码,它将 Facebook 朋友、喜欢和用户个人资料等信息保存到我的数据库中。个人资料包括用户的位置和性别,但它作为字符串保存到数据库中,因此我无法提取它。
@graph = Koala::Facebook::GraphAPI.new(current_user.token)
current_user.profile = @graph.get_object("me")
current_user.likes = @graph.get_connections("me", "likes")
current_user.friends = @graph.get_connections("me", "friends")
current_user.save
进入控制台,我可以通过以下方式获取最后一个用户的个人资料:
u = User.last.profile
但这并不能让我专门调用该位置,例如:
User.last.profile.location
用户表的样子
create_table "users", :force => true do |t|
t.string "provider"
t.string "uid"
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.string "token"
t.string "likes"
t.string "profile"
t.string "location"
t.string "interests"
t.string "birthday"
t.string "activities"
t.string "friends"
end
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 facebook-graph-api koala