0

在我的控制器中,我有以下操作

  def twitter
    client = TwitterOAuth::Client.new(
        :consumer_key => ENV['TWITTER_KEY'],
        :consumer_secret => ENV['TWITTER_SECRET']
    )

    request_token = client.request_token(oauth_callback: "http://myawesomeapp.herokuapp.com/create_users/get_twitter_info")

    redirect_to "https://www.twitter.com/oauth/authenticate?oauth_token=#{request_token.params[:oauth_token]}"
  end

  def get_twitter_info 
    redirect_to "https://www.twitter.com/oauth/access_token?oauth_verifier=#{params[:oauth_verifier]}&oauth_token=#{params[:oauth_token]}"
  end

  def results
  end

在我的 Twitter 应用程序设置中,我已将 Access 设置为Read Only并选中Allow this application to be used to Sign in with Twitter. 为什么会回来

Invalid Request Token

当它到达https://twitter.com/oauth/access_token页面时?

4

1 回答 1

0
In Main function You write Simply this code



    redirect_url = "http://myawesomeapp.herokuapp.com/create_users/get_twitter_info"

    url = URI.parse(URI.encode(redirect_url.strip))

   consumer_key=consumer key
   consumer_secret=consumer secret

    oauth = OAuth::Consumer.new(consumer_key, consumer_secret,
                             { :site => "http://api.twitter.com" })
    request_token = oauth.get_request_token(:oauth_callback => url)
    session[:twitter_token] = request_token.token
    session[:twitter_secret] = request_token.secret

并且在

获取推特信息

你写的函数

consumer_key=consumer key
 consumer_secret=consumer secret
oauth = OAuth::Consumer.new(consumer_key,consumer_secret,
                             { :site => "http://api.twitter.com" })
request_token = OAuth::RequestToken.new(oauth, session[:twitter_token],                                          session[:twitter_secret])
@access_token = request_token.get_access_token(
                 :oauth_verifier => params[:oauth_verifier])

但请记住,在您提到的 twitter 应用程序设置callback url

http://myawesomeapp.herokuapp.com/create_users/get_twitter_info

于 2013-08-09T07:20:58.950 回答