Para fazer uma chamada de API com um token oAuth
Eu quero fazer o pedido de oAuth em Ruby. Eu usei alguns exemplos, mas nenhum deles usouoauth_token_secret and oauth_token
para fazer um pedido, eles só usaramconsumer_key
econsumer_secret
para obteroauth_token_secret
eoauth_token
. Mas eu já tenhooauth_token_secret
eoauth_token
.
Por exemplo, este eu tentei usar
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
No meu caso, existem 4 chaves secretas:
consumer_key = "anonymous"
consumer_secret = "anonymous"
oauth_token_secret = "fdsfdsfdfdsfds"
oauth_token = "fdsfdsfdfdsfdsdsdsdsdsdsds"
Então, o que eu preciso fazer é fazer uma solicitação de API para o URL específico com alguns parâmetros get adicionais e token oAuth e obter a resposta.
Como faço isso em Ruby?