8
我想在Ruby中发出oAuth请求。我浏览了一些例子,但他们没有使用oauth_token_secret and oauth_token
来提出请求,他们只使用consumer_key
和consumer_secret
得到oauth_token_secret
和oauth_token
。但我已经有oauth_token_secret
和oauth_token
。使用oAuth令牌进行API调用
例如,这一次我试图用
require 'rubygems'
require 'oauth'
consumer = OAuth::Consumer.new(consumer_key, consumer_secret,
{
:site=> "https://www.google.com",
:scheme=> :header,
:http_method=> :post,
:request_token_path => "/accounts/OAuthGetRequestToken",
:access_token_path => "/accounts/OAuthGetAccessToken",
:authorize_path=> "/accounts/OAuthAuthorizeToken",
:signature_method=>"RSA-SHA1"},
# :private_key_file=>PATH_TO_PRIVATE_KEY
)
request_token = consumer.get_request_token()
puts "Visit the following URL, log in if you need to, and authorize the app"
puts request_token.authorize_url
puts "When you've authorized that token, enter the verifier code you are assigned:"
verifier = gets.strip
puts "Converting request token into access token..."
access_token=request_token.get_access_token(:oauth_verifier => verifier)
puts "access_token.token --> #{access_token.token}" # But I initially have it
puts "access_token.secret --> #{access_token.secret}" # But I initially have it
在我的情况下,有4个密钥:
consumer_key = "anonymous"
consumer_secret = "anonymous"
oauth_token_secret = "fdsfdsfdfdsfds"
oauth_token = "fdsfdsfdfdsfdsdsdsdsdsdsds"
所以我需要做的是,做一个API请求到一定的URL与一些额外的获取参数和oAuth令牌,并得到答案。
我该如何在Ruby中做到这一点?
我不需要采用OAuth :: AccessToken,因为我已经有了oauth_secret和oauth_token。 –
@AlanDert我知道。使用你在这里得到的对象:'access_token = request_token.get_access_token(:oauth_verifier => verifier)' – oldergod
什么是验证者?你能举出完整的例子吗?请注意,Typhoeus有错误,我无法使用它。 –