Chcę utworzyć żądanie OAuth w Ruby. Przesłuchałem kilka przykładów, ale żaden z nich nie użył oauth_token_secret and oauth_token
, aby złożyć wniosek, użyli tylko consumer_key
i consumer_secret
, aby uzyskać oauth_token_secret
i oauth_token
. Ale mam już oauth_token_secret
i oauth_token
.Aby wykonać wywołanie API za pomocą tokenu OAuth
Na przykład, ten próbowałem użyć
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
W moim przypadku, istnieją 4 tajnych kluczy:
consumer_key = "anonymous"
consumer_secret = "anonymous"
oauth_token_secret = "fdsfdsfdfdsfds"
oauth_token = "fdsfdsfdfdsfdsdsdsdsdsdsds"
Więc co muszę zrobić to, aby złożyć zamówienie API do określonego adresu URL z dodatkowymi parametrami pobierania i tokenem OAuth i uzyskania odpowiedzi.
Jak to zrobić w Ruby?
Nie muszę pobierać OAuth :: AccessToken, ponieważ mam już oauth_secret i oauth_token. –
@AlanDert Wiem. Użyj obiektu, który tu uzyskasz: 'access_token = request_token.get_access_token (: oauth_verifier => verifyier)' – oldergod
Co to jest weryfikator? Czy możesz podać pełny przykład? Pamiętaj, że Typhoeus ma błąd, nie mogę go użyć. –