【发布时间】:2012-08-01 09:18:47
【问题描述】:
我想使用Koala Gem 连接到 Facebook api,但遇到了一些问题。
在使用 Koala 之前,我使用omniauth-facebook 来实现我的应用的 SSO。
然后我在 Gemfile 中添加了gem koala 并运行捆绑安装。
在我的`user.rb'中
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
def facebook
@facebook = Koala::Facebook::API.new(oauth_token)
end
然后我去控制台。
u = User.first
User Load (0.5ms) SELECT "users".* FROM "users" LIMIT 1
=> #<User id: 1, provider: "facebook", uid: "100003544640331", name: "Gary Lai", oauth_token: "AAAB9iQ1zm2oBAA1w3DFBZBC2V73uheQCs43dHpOu1LYsYixqvu...", oauth_expires_at: "2012-10-02 09:55:39", created_at: "2012-07-27 16:41:18", updated_at: "2012-08-03 09:55:42">
有效。
但是,当我按照 kaola 教程进行操作时,我收到了此错误消息。
u.facebook.get_object("me")
NoMethodError: undefined method `get_object' for #<Koala::Facebook::API:0x007fb07ab1e108>from (irb):8
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
为什么我收到此错误消息?
【问题讨论】:
-
终于解决了这个问题。因为我的考拉版本是 1.0。因此我必须使用
gem 'koala', :git => 'https://github.com/arsduo/koala.git' -
好的,请自行指定答案,并检查。还有为什么不用release koala(1.6.0)?
标签: ruby-on-rails-3 facebook-graph-api koala