我正在尝试获取访问密钥,但我无法使其正常工作。 ``request_token.get_access_token is giving me
401未授权(OAuth :: Unauthorized)error. I copy the authorize_url into my browser, allow the application, I receive some kind of PIN from twitter but after hitting enter in my script I always get 401 error. I did some search and I found this helped
access_token = request_token.get_access_token(:oauth_verifier => params [:oauth_verifier])but it is giving me
未定义的局部变量或方法params' for main:Object (NameError)
gem 'oauth'
require 'oauth/consumer'
consumer_key = 'your key'
consumer_secret ='your secret'
consumer=OAuth::Consumer.new "consumer_key",
"consumer_secret",
{:site=>"http://twitter.com"}
request_token = consumer.get_request_token
puts request_token.token
puts request_token.secret
puts request_token.authorize_url
puts "Hit enter when you have completed authorization."
STDIN.gets
access_token = request_token.get_access_token
#access_token = request_token.get_access_token(:oauth_verifier => params[:oauth_verifier])
puts access_token.token
puts access_token.secret
puts
puts access_token.inspect
答案 0 :(得分:5)
我遇到了完全相同的问题。 替换:
STDIN.gets
使用:
pin = (gets.chomp).to_i
to_i转换为整数,该整数也用于剥离空格。 然后,您需要在尝试获取访问令牌时指定引脚。如果您不这样做,则没有证据表明用户已允许您的申请。
access_token = request_token.get_access_token(:oauth_verifier => pin)
puts "Access Token : " + access_token.token
puts "Access Secret : " + access_token.secret