宝石考拉undefined方法'get_object'

时间:2012-08-03 10:19:23

标签: ruby-on-rails-3 facebook-graph-api koala

我想使用Koala Gem连接到Facebook api,但我遇到了一些问题。

在我使用Koala之前,我使用omniauth-facebook来实现我的应用的SSO。

然后我在Gemfile中添加gem koala并运行bundle install。

在我的`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 :(得分:0)

最后,我解决了这个问题。因为我的考拉版本是1.0。因此,我必须使用gem 'koala', :git => 'https://github.com/arsduo/koala.git'