使用OAuthBase.cs的Yahoo Oauth API

Chr*_*Gau 2 c# api yahoo oauth httprequest

我目前正在使用oauth.net上提供的OAuthBase.cs帮助程序类来实现OAuth与Yahoo!交谈.幻想API.我目前停留在第5步(使用访问令牌/访问密钥来调用API服务).

我成功完成了第4步,但似乎无法创建实际的服务调用. 文件有限; 我应该使用什么参数?我得到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())
{
    ....
}
Run Code Online (Sandbox Code Playgroud)

url我正在尝试制作的api电话在哪里,consumerKey/ consumerSecret是我注册Yahoo!时给我的钥匙,和accessToken/ accessTokenSecret是从request_auth第4步返回的响应.我做错了什么?

提前致谢

编辑:12/14 - 对于那些不熟悉OAuthBase的人来说,它本质上是一个由1生成签名的库.整合所有url /参数(consumerkey,token,tokenSecret,httpMethod,nonce,time等),对其进行排序,以及规范化url /参数; 2.将consumerSecret'&'tokenSecret编码为HMACSHA1密钥; 3.计算hmacsha1键的哈希值

Joh*_*zén 5

以下是使用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);
    }
Run Code Online (Sandbox Code Playgroud)