未定义方法“authorize_from_request”在 Ruby on Rails 3 中使用 OAuth 和 Twitter Gem

发布于 2024-11-05 16:46:40 字数 2059 浏览 0 评论 0原文

我收到以下错误:

未定义的方法`authorize_from_request'

基于此处的文档: http: //oauth.rubyforge.org/rdoc/classes/OAuth/Consumer.html 该方法不存在,但我看到这里使用了该方法: http://teachmetocode.com/screencasts/oauth-with-the-twitter-宝石/ 和 所以我猜它不久前已被弃用,但我似乎无法 找到它的替代品,并想知道我还能采取什么其他方法 解决这个问题吗?

提前致谢!

控制器代码:(

    class TwitterController < ApplicationController
      def index

      end

      def login
        oauth_request_token = oauth.get_request_token(:oauth_callback => "http://gnome.local/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
        oauth.authorize_from_request(session[:request_token], session[:request_secret], params[:oauth_verifier])

        @client = Twitter::Client.new(oauth).verify_credentials

        session[:request_token] = nil
        session[:request_secret] = nil
        oauth_access_token = oauth.get_access_token
        @oauth_token = session[:oauth_token] = oauth_access_token.token
        session[:oauth_secret] = oauth_access_token.secret
      end

      def client
        oauth.authorize_from_access(session[:auth_token])
      end

      def oauth
        @oauth ||= OAuth::Consumer.new(APP_CONFIG[:twitter][:consumer_key], APP_CONFIG[:twitter][:consumer_secret], :site => "http://api.twitter.com", :request_endpoint => "http://api.twitter.com", :sign_in => true);
      end

    end

原始帖子:http://groups.google.com/组/oauth-ruby/browse_thread/thread/614b27e4f5d80fab

Im getting the following error:

undefined method `authorize_from_request'

Based on the documenation here: http://oauth.rubyforge.org/rdoc/classes/OAuth/Consumer.html
That method doesnt exist, but I saw this method used here:
http://teachmetocode.com/screencasts/oauth-with-the-twitter-gem/ and
so I'm guessing it was deprecated some time ago, but I can't seem to
find its replacement and was wondering what other way could I go about
solving this issue?

Thanks in Advance!

Controller Code:

    class TwitterController < ApplicationController
      def index

      end

      def login
        oauth_request_token = oauth.get_request_token(:oauth_callback => "http://gnome.local/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
        oauth.authorize_from_request(session[:request_token], session[:request_secret], params[:oauth_verifier])

        @client = Twitter::Client.new(oauth).verify_credentials

        session[:request_token] = nil
        session[:request_secret] = nil
        oauth_access_token = oauth.get_access_token
        @oauth_token = session[:oauth_token] = oauth_access_token.token
        session[:oauth_secret] = oauth_access_token.secret
      end

      def client
        oauth.authorize_from_access(session[:auth_token])
      end

      def oauth
        @oauth ||= OAuth::Consumer.new(APP_CONFIG[:twitter][:consumer_key], APP_CONFIG[:twitter][:consumer_secret], :site => "http://api.twitter.com", :request_endpoint => "http://api.twitter.com", :sign_in => true);
      end

    end

(Original Post: http://groups.google.com/group/oauth-ruby/browse_thread/thread/614b27e4f5d80fab)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺深海 2024-11-12 16:46:40

遇到同样的问题,解决方案是根据(旧)Twitter gem:

request_token.get_access_token(oauth_verifier: params[:oauth_verifier])

Got the same problem, the solution is to use according to the (old) Twitter gem:

request_token.get_access_token(oauth_verifier: params[:oauth_verifier])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文