2
我想用Koala Gem連接到Facebook api,但我遇到了一些問題。寶石考拉未定義的方法'get_object'
在我使用考拉之前,我使用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
然後我去consoele。
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'' – 2012-08-03 17:26:34
好的,請自行指定答案,然後檢查它。爲什麼你不使用釋放考拉(1.6.0)? – 2013-11-23 10:40:32