Yahoo Oauth in Ruby API Request - Signature Invalid -
i have gotten access token , access secret. i'm trying make api request oauth information.
i'm following alongside yahoo docs (not helpful): https://developer.yahoo.com/oauth/guide/oauth-make-request.html https://developer.yahoo.com/oauth/guide/oauth-signing.html
also, i'm trying follow example closely: https://gist.github.com/cheenu/1469815
here code: (i split long url convenience)
require 'cgi' require 'base64' require 'openssl' url = "http://fantasysports.yahooapis.com/fantasy/v2/game/nfl" parameters = "format=json &realm=yahooapis.com &oauth_consumer_key=#{rails.application.secrets.yhoo_consumer_key} &oauth_nonce=#{securerandom.hex} &oauth_signature_method=hmac-sha1 &oauth_timestamp=#{time.now.to_i} &oauth_token=#{apivar.final_oauth_token} #the access token &oauth_version=1.0" base_string = 'get&' + cgi.escape(url) + '&' + cgi.escape(parameters) oauth_signature = cgi.escape(base64.encode64("#{openssl::hmac.digest('sha1', apivar.final_oauth_secret + "&", base_string)}").chomp) #apivar.final_oauth_secret access token secret - should putting there? testable_url = url + '?' + parameters + '&oauth_signature=' + oauth_signature p testable_url response = httparty.get(testable_url)
my response gives me "signature_invalid."
what doing wrong?
thank you!
url = "http://fantasysports.yahooapis.com/fantasy/v2/league/{league-key}/players" parameters = "format=json&oauth_consumer_key=#{rails.application.secrets.yhoo_consumer_key}&oauth_nonce=#{securerandom.hex}&oauth_signature_method=hmac-sha1&oauth_timestamp=#{time.now.to_i}&oauth_token=#{apivar.final_oauth_token}&oauth_version=1.0&realm=yahooapis.com" base_string = 'get&' + cgi.escape(url) + '&' + cgi.escape(parameters) secret = "#{rails.application.secrets.yhoo_consumer_secret}&#{apivar.final_oauth_secret}" oauth_signature = cgi.escape(base64.encode64("#{openssl::hmac.digest('sha1', secret, base_string)}").chomp) testable_url = url + '?' + parameters + '&oauth_signature=' + oauth_signature p testable_url response = httparty.get(testable_url) #{rails.application.secrets.yhoo_consumer_secret}&#{apivar.final_oauth_secret}" - correct secret key
the parameters have ordered alphabetically! also, secret key yahoo consumer secret plus final oauth secret!
Comments
Post a Comment