【发布时间】:2014-10-10 21:28:14
【问题描述】:
我已经成功获得了访问令牌和访问密码。现在我正在尝试使用 OAuth 信息发出 API 请求。
我正在关注 yahoo 文档(不是很有帮助): https://developer.yahoo.com/oauth/guide/oauth-make-request.html https://developer.yahoo.com/oauth/guide/oauth-signing.html
另外,我正在尝试密切关注此示例: https://gist.github.com/cheenu/1469815
这里是代码:(为了方便,我把长网址分开了)
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 is the access token secret - is that what I should be putting there?
testable_url = url + '?' + parameters + '&oauth_signature=' + oauth_signature
p testable_url
response = HTTParty.get(testable_url)
我的回复是“signature_invalid”。
我做错了什么?
谢谢!
【问题讨论】:
标签: ruby-on-rails ruby api oauth yahoo-api