Yahoo BOSS v2 api を使用して簡単な検索ページを作成しようとしていますが、OAuth が正しく機能しません。私はすべてのキーなどを持っており、http://oauth.googlecode.com/svn/code/csharp/OAuthBase.csで OAuth 用の C# クラスをダウンロードしましたが、エラーが発生し続けます。
次のことを試しました。
JavaScript 関数が yahoo ボスのクエリ文字列を作成し、PageMethods.getYahoo(query string, responseFunction); につながります。
これがコードビハインドです
[WebMethod]
public static string getYahoo(string url)
{
String result;
OAuthBase oauth = new OAuthBase();
Uri uri = new Uri("http://mysite.com");
string a, qstring = "";
string signature = oauth.GenerateSignature(uri, "-my consumer key-", "-my
secret-", out a, out qstring);
url = url.Replace("{oauth}", qstring + "oauth_signature=" + signature);
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
objResponse = objRequest.GetResponse();
using (StreamReader sr =
new StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
sr.Close();
}
return result;
}
oAuthBase クラスの GenerateSignature メソッドは次のとおりです。
public string GenerateSignature(Uri url, string consumerKey, string
consumerSecret, out string normalizedUrl, out string
normalizedRequestParameters)
{
normalizedUrl = null;
normalizedRequestParameters = null;
string signatureBase = GenerateSignatureBase(url, consumerKey,null
,null,null,GenerateTimeStamp(),GenerateNonce(), HMACSHA1SignatureType, out
normalizedUrl, out normalizedRequestParameters);
HMACSHA1 hmacsha1 = new HMACSHA1();
hmacsha1.Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}",
UrlEncode(consumerSecret), ""));
return GenerateSignatureUsingHash(signatureBase, hmacsha1);
}
しかし、エラーが発生し続けます:
Message: Sys.Net.WebServiceFailedException: The server method 'getYahoo' failed
with the following error: System.Net.WebException-- The remote server returned
an error: (401) Unauthorized.
Line: 6934
Char: 21
Code: 0
ここで誰かが助けてくれることを願っています...!