【发布时间】:2012-12-11 07:03:57
【问题描述】:
我目前正在使用 oauth.net 上提供的 OAuthBase.cs 帮助程序类来实现 OAuth 以与 Yahoo! 通信。幻想 API。我目前停留在第 5 步(使用访问令牌/访问密钥调用 API 服务)。
我成功完成了Step 4,但似乎无法创建实际的服务调用。 The documentation 是有限的;我应该使用什么参数?我收到 401 或 400 http 错误。我正在通过以下方式生成我的签名:
url = new Uri("http://query.yahooapis.com/v1/public/yql?q=select * from fantasysports.teams.roster.stats where team_key='nba.l.52669.t.5' and week='5' and stats_type='week' and stats_week='5'&format=json");
signature = oauth.GenerateSignature(url, string.Empty, consumerKey, consumerSecret, accessToken, accessTokenSecret, "GET", time, string.Empty, nonce, OAuth.OAuthBase.SignatureTypes.HMACSHA1, out normalizedUrl, out normalizedRequestParameters);
using (var y = WebRequest.Create(string.Format("{0}?{1}&oauth_signature={2}", normalizedUrl, normalizedRequestParameters, signature)).GetResponse())
{
....
}
url 是我尝试进行的 api 调用,consumerKey / consumerSecret 是我注册 Yahoo! 时给我的密钥,accessToken / accessTokenSecret 是响应在第 4 步从request_auth 返回。我做错了什么?
提前致谢
编辑:12/14 - 对于那些不熟悉 OAuthBase 的人来说,它本质上是一个通过以下方式生成签名的库 1. 合并所有的url/参数(consumerkey、token、tokenSecret、httpMethod、nonce、time等),排序,规范化url/参数; 2.将consumerSecret '&' tokenSecret编码为HMACSHA1密钥; 3.计算hmacsha1 key的hash
【问题讨论】:
标签: c# api oauth httprequest yahoo