开发者社区> 问答> 正文

通过 omniauth 使用 twitter 遇到的问题

一直很想试下omniauth 我很菜,找到了这篇文章 http://railscasts.com/episodes/241-simple-omniauth 按其过程一路下来,注册好'CONSUMER_KEY', 'CONSUMER_SECRET' 最后rake routes时,说不能初始化: uninitialized constant OmniAuth::Strategies::Twitter 查到原因是还要添加omniauth-twitter这个gem gem 'omniauth-twitter'

这时,

rake routes时: ``` /auth/:provider/callback(.:format) {:controller=>"sessions", :action=>"create"} signout /signout(.:format) {:controller=>"sessions", :action=>"destroy"}

当我访问http://localhost:3000/auth/twitter 时,成功跳转到twitter去登录,登录成功后返回时,出错:

```Started GET "/auth/twitter/callback?oauth_token=1RubhwlvzjEE9mfYIGiKD1ZIGUNBDFqgkLfV4jo6bU&oauth_verifier=OEUA0qLLZNpYunwDL1BnWSydCo4IbnUYqOCTzZ33goo" for 127.0.0.1 at 2011-11-26 22:32:30 +0800
  Processing by SessionsController#create as HTML
  Parameters: {"oauth_token"=>"1RubhwlvzjEE9mfYIGiKD1ZIGUNBDFqgkLfV4jo6bU", "oauth_verifier"=>"OEUA0qLLZNpYunwDL1BnWSydCo4IbnUYqOCTzZ33goo", "provider"=>"twitter"}
  User Load (0.5ms)  SELECT `users`.* FROM `users` WHERE `users`.`provider` = 'twitter' AND `users`.`uid` = '18209844' LIMIT 1
Completed 500 Internal Server Error in 71ms

Started GET "/auth/failure?message=invalid_response" for 127.0.0.1 at 2011-11-26 22:32:34 +0800
ActionController::RoutingError (No route matches [GET] "/auth/failure"):

展开
收起
心有灵_夕 2019-12-29 00:45:25 910 0
1 条回答
写回答
取消 提交回答
  • 原因我查了很久,一直以为是twtter处配置的问题,后来,看了log,请求已经成功返回,带有验证后的数据,问题出在 ```user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)

    继续log往下找时,在User中的create_with_omniauth方法中,看到有auth["provider"],auth["uid"]以及auth["user_info"]["name"], 好吧,我将auth打印出来,我找到了provider,uid,就是找不到user_info,但我找到了name... 我觉得我已经找到问题所在,auth["user_info"]["name"] 修改成 auth["name"] 后,重试果然成功

    2019-12-29 00:45:39
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
facebook 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载