2013-04-09 98 views
1

我正在嘗試將Twitter集成到我的網站上,以便用戶可以使用Twitter註冊並登錄,但這裏是我在訪問http://localhost:3000/twitter/login時發生的錯誤錯誤的參數數量(2爲1) - TwitterController中的參數錯誤#登錄

ArgumentError in TwitterController#login 

wrong number of arguments (2 for 1) 

這裏是Twitter的控制器至今

class TwitterController < ApplicationController 
    def index 
    end 

    def login 
    oauth.set_callback_url("http://#{request.host}/twitter/finalize") 

    session[:request_token] = oauth.request_token.token 
    session[:request_secret] = oauth.request_token.secret 

    redirect_url = oauth.request_token.authorize_url 
    redirect_url = "http://" + redirect_url unless redirect_url.match(/^http:\/\//) 
    redirect_to redirect_url 
    end 

    def finalize 
    end 

    def oauth 
    @oauth ||= Twitter::Client.new(APP_CONFIG[:twitter][:consumer_key], APP_CONFIG[:twitter][:consumer_secret]) 
    end 
end 

什麼是從控制器內部造成的呢?

完全跟蹤:

twitter (4.6.2) lib/twitter/client.rb:51:in `initialize' 
app/controllers/twitter_controller.rb:20:in `new' 
app/controllers/twitter_controller.rb:20:in `oauth' 
app/controllers/twitter_controller.rb:6:in `login' 
actionpack (3.2.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action' 
actionpack (3.2.3) lib/abstract_controller/base.rb:167:in `process_action' 
actionpack (3.2.3) lib/action_controller/metal/rendering.rb:10:in `process_action' 
actionpack (3.2.3) lib/abstract_controller/callbacks.rb:18:in `block in process_action' 
activesupport (3.2.3) lib/active_support/callbacks.rb:425:in `_run__1049760818__process_action__595446911__callbacks' 
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback' 
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' 
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks' 
actionpack (3.2.3) lib/abstract_controller/callbacks.rb:17:in `process_action' 
actionpack (3.2.3) lib/action_controller/metal/rescue.rb:29:in `process_action' 
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' 
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `block in instrument' 
activesupport (3.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `instrument' 
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:29:in `process_action' 
actionpack (3.2.3) lib/action_controller/metal/params_wrapper.rb:205:in `process_action' 
activerecord (3.2.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action' 
actionpack (3.2.3) lib/abstract_controller/base.rb:121:in `process' 
actionpack (3.2.3) lib/abstract_controller/rendering.rb:45:in `process' 
actionpack (3.2.3) lib/action_controller/metal.rb:203:in `dispatch' 
actionpack (3.2.3) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' 
actionpack (3.2.3) lib/action_controller/metal.rb:246:in `block in action' 
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `call' 
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `dispatch' 
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:36:in `call' 
journey (1.0.4) lib/journey/router.rb:68:in `block in call' 
journey (1.0.4) lib/journey/router.rb:56:in `each' 
journey (1.0.4) lib/journey/router.rb:56:in `call' 
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:600:in `call' 
warden (1.2.1) lib/warden/manager.rb:35:in `block in call' 
warden (1.2.1) lib/warden/manager.rb:34:in `catch' 
warden (1.2.1) lib/warden/manager.rb:34:in `call' 
actionpack (3.2.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' 
rack (1.4.5) lib/rack/etag.rb:23:in `call' 
rack (1.4.5) lib/rack/conditionalget.rb:25:in `call' 
actionpack (3.2.3) lib/action_dispatch/middleware/head.rb:14:in `call' 
actionpack (3.2.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call' 
actionpack (3.2.3) lib/action_dispatch/middleware/flash.rb:242:in `call' 
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context' 
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call' 
actionpack (3.2.3) lib/action_dispatch/middleware/cookies.rb:338:in `call' 
activerecord (3.2.3) lib/active_record/query_cache.rb:64:in `call' 
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call' 
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call' 
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run__770706334__call__235543105__callbacks' 
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback' 
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_call_callbacks' 
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks' 
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:in `call' 
actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in `call' 
actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call' 
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' 
railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app' 
railties (3.2.3) lib/rails/rack/logger.rb:16:in `call' 
actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call' 
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call' 
rack (1.4.5) lib/rack/runtime.rb:17:in `call' 
activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call' 
rack (1.4.5) lib/rack/lock.rb:15:in `call' 
actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call' 
railties (3.2.3) lib/rails/engine.rb:479:in `call' 
railties (3.2.3) lib/rails/application.rb:220:in `call' 
rack (1.4.5) lib/rack/content_length.rb:14:in `call' 
railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call' 
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service' 
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' 
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' 
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' 
+0

任何機會,你有堆棧跟蹤? – 2013-04-09 01:56:37

+0

剛剛在 – syk 2013-04-09 02:06:36

回答

0

使用這個API的正確方法(根據其documentation)是通過傳遞,而不是「真實」的方法參數哈希選項參數:

def oauth 
    @oauth ||= Twitter::Client.new(:consumer_key => APP_CONFIG[:twitter][:consumer_key], :consumer_secret => APP_CONFIG[:twitter][:consumer_secret]) 
    end 
+0

上面發佈了完整跟蹤,你知道我需要爲twitter集成定義「set_callback_url」嗎?我現在得到這個錯誤'未定義的方法set_callback_url' – syk 2013-04-09 02:37:44

+0

退房http://stackoverflow.com/questions/2234880/twitter-api-oauth-gem-not-getting-callback – 2013-04-09 02:42:59

+0

如果你仍然有麻煩後嘗試這種解決方案,我建議將這個問題標記爲已接受,並寫出一個清晰地說明你的新問題的新問題,因爲這個問題可能會得到解決 – 2013-04-09 02:43:41

相關問題