【问题标题】:Yahoo Oauth API with OAuthBase.cs带有 OAuthBase.cs 的 Yahoo Oauth API
【发布时间】: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


    【解决方案1】:

    这是一些使用 OAuth 访问 Yahoo API 的工作代码(在本例中为 BOSS Geo API)

        [Test]
        public void MakeCallToBossGeoApi()
        {
            string result;
            var uri = new Uri(@"http://yboss.yahooapis.com/geo/placefinder?country=SE&flags=J&locale=sv_SE&postal=41311");
            var o = new OAuthBase();
            string nonce = o.GenerateNonce();
            var timestamp = o.GenerateTimeStamp();
    
            string normalizedUrl;
            string normalizedParameters;
            string signature = HttpUtility.UrlEncode(
                o.GenerateSignature(uri,
                                    "yourconsumerkeyhere",
                                    "yourconsumersecrethere", null, null, "GET",
                                    timestamp, nonce, out normalizedUrl,
                                    out normalizedParameters));
    
            uri = new Uri(normalizedUrl +"?"+ normalizedParameters + "&oauth_signature=" + signature );
    
            using (var httpClient = new WebClient())
            {
                result = httpClient.DownloadString(uri.AbsoluteUri);
            }
    
            Console.WriteLine(result);
        }
    

    【讨论】:

      猜你喜欢
      • 2018-10-05
      • 1970-01-01
      • 2018-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-04
      相关资源
      最近更新 更多