undefined method `web_server' for #<OAuth2::ClIEnt:0x00000005211d58>
跟踪显示
oa-oauth (0.0.1) lib/omniauth/strategIEs/oauth2.rb:18:in `request_phase'oa-oauth (0.0.1) lib/omniauth/strategIEs/facebook.rb:28:in `request_phase'oa-core (0.0.5) lib/omniauth/strategy.rb:25:in `call!'oa-core (0.0.5) lib/omniauth/strategy.rb:19:in `call'oa-core (0.0.5) lib/omniauth/builder.rb:22:in `call'warden (1.0.5) lib/warden/manager.rb:35:in `block in call'warden (1.0.5) lib/warden/manager.rb:34:in `catch'warden (1.0.5) lib/warden/manager.rb:34:in `call'
还有其他人经历过这个吗?
PS.我正在使用以下宝石:
gem 'oa-oauth',:require => 'omniauth/oauth'gem 'oauth2'
我没有使用完整的omniauth gem,因为它的可寻址依赖性与其他gem相冲突.
解决方法 我在rails应用程序上尝试使用facebook_oauth(https://github.com/moomerman/facebook_oauth)时遇到了同样的问题.花了一个小时左右尝试更改代码后,我意识到直接使用oauth2可能更容易.我解决了问题,现在不需要那个中间库.这是如何做:在Gemfile中添加
gem 'oauth2'
然后跑
捆绑更新
然后,在您的login_via_facebook方法中,您可以手动构建对话框uri,也可以在这些行中使用oauth客户端:
oauth_clIEnt = OAuth2::ClIEnt.new(APPliCATION_ID,APPliCATION_SECRET,{ :authorize_url => 'https://www.facebook.com/dialog/oauth'})redirect_to oauth_clIEnt.authorize_url({ :clIEnt_ID => APPliCATION_ID,:redirect_uri => YOUR_REDIRECT_URL})
如果需要请求其他权限,请在authorize_url调用中指定scope param:
redirect_to oauth_clIEnt.authorize_url({ :clIEnt_ID => APPliCATION_ID,:redirect_uri => YOUR_REDIRECT_URL,:scope => 'offline_access,email'})
然后,在处理YOUR_REDIRECT_URL的方法中(我称之为我的login_via_facebook_callback),执行以下 *** 作:
oauth_clIEnt = OAuth2::ClIEnt.new(APPliCATION_ID,{ :site => 'https://graph.facebook.com',:token_url => '/oauth/access_token'})begin access_token = oauth_clIEnt.get_token({ :clIEnt_ID => APPliCATION_ID,:clIEnt_secret => APPliCATION_SECRET,:code => params[:code],:parse => :query }) access_token.options[:mode] = :query access_token.options[:param_name] = :access_token facebook_user_info = access_token.get('/me',{:parse => :Json}).parsedrescue Error => e # You will need this error during development to make progress :) #logger.error(e)end
现在facebook_user_info有基本的用户信息!
总结以上是内存溢出为你收集整理的ruby – 无法使用facebook进行身份验证:OAuth2的未定义方法’web_server’?全部内容,希望文章能够帮你解决ruby – 无法使用facebook进行身份验证:OAuth2的未定义方法’web_server’?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)