2

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

在我使用考拉之前,我使用omniauth-facebook来实现我的应用程序的SSO。

然后我gem koala在 Gemfile 中添加并运行捆绑安装。

在我的`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>'

为什么我收到此错误消息?

4

1 回答 1

0

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

于 2015-03-13T05:35:20.410 回答