OAuth :: Unauthorized 401 int twitter-omniauth gem

rob*_*ert 15 twitter-gem twitter-oauth ruby-on-rails-3

我一直在尝试使用twitter-omniauthgem 验证用户的最后几天,但没有成功.(与facebook的身份验证工作完美)

我一直在收到401 Unauthorized错误.

我搜索stackoverflow,但没有一个答案可以解决我的问题.

我尝试时到达Twitter登录http://127.0.0.1/users/auth/twitter.我登录后,我被重定向到http://127.0.0.1/users/auth/twitter/callback未经授权的错误.

我在twitter中输入了回调网址

http://127.0.0.1/users/auth/twitter/callback

rake routes 产量

new_user_session GET    /users/sign_in(.:format)               {:action=>"new", :controller=>"devise/sessions"}
                user_session POST   /users/sign_in(.:format)               {:action=>"create", :controller=>"devise/sessions"}
        destroy_user_session DELETE /users/sign_out(.:format)              {:action=>"destroy", :controller=>"devise/sessions"}
      user_omniauth_callback        /users/auth/:action/callback(.:format) {:action=>/twitter|facebook/, :controller=>"users/omniauth_callbacks"}
               user_password POST   /users/password(.:format)              {:action=>"create", :controller=>"devise/passwords"}
           new_user_password GET    /users/password/new(.:format)          {:action=>"new", :controller=>"devise/passwords"}
          edit_user_password GET    /users/password/edit(.:format)         {:action=>"edit", :controller=>"devise/passwords"}
                             PUT    /users/password(.:format)              {:action=>"update", :controller=>"devise/passwords"}
    cancel_user_registration GET    /users/cancel(.:format)                {:action=>"cancel", :controller=>"devise/registrations"}
           user_registration POST   /users(.:format)                       {:action=>"create", :controller=>"devise/registrations"}
       new_user_registration GET    /users/sign_up(.:format)               {:action=>"new", :controller=>"devise/registrations"}
      edit_user_registration GET    /users/edit(.:format)                  {:action=>"edit", :controller=>"devise/registrations"}
                             PUT    /users(.:format)                       {:action=>"update", :controller=>"devise/registrations"}
                             DELETE /users(.:format)                       {:action=>"destroy", :controller=>"devise/registrations"}
                       login        /login(.:format)                       {:action=>"login", :controller=>"home"}
                        root        /                                      {:controller=>"home", :action=>"index"}
Run Code Online (Sandbox Code Playgroud)

如果您需要更多信息,我会提供.请帮我解决这个问题.

小智 17

我今天遇到了这个问题,发现我必须在我的应用程序下的dev.twitter.com设置中设置一个回调URL.因此,请检查您是否设置了回调URL设置,我将其设置为我的预期生产地址,当在本地以开发模式运行时,它会重定向.

它在回调网址输入框中提到如果留空则会限制应用程序使用回调网址.


ejl*_*in1 13

当我来自localhost时,我很确定我遇到了这个问题...

这篇文章说它们允许它,但如果内存正确地为我服务,我必须使用外部可访问的URL.当我测试我的oauth时,我使用了DynDns并在我的路由器中打开了一个端口.

  • 如果您使用的是localhost.如果您使用网址缩短器,它会起作用. (5认同)