0
我一直在尝试使用雅虎BOSS v2 api创建一个简单的搜索页面,但无法使OAuth正常工作。我有所有的密钥等,并在http://oauth.googlecode.com/svn/code/csharp/OAuthBase.cs下载了OAuth的C#类,但我不断收到错误。在.net/C中使用OAuth实现雅虎BOSS v2时出现问题#
我们已经试过如下:
javascript函数建立了一个雅虎老板查询字符串,然后导致 PageMethods.getYahoo(查询字符串,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
我在这里希望有人能帮帮我...!
你在[email protected]电子邮件列表中?几天前他们发布了一个工作示例(未经我检查),它是c#。你想在这里发布吗? – 2011-06-01 12:23:53
是路易斯,请在这里发布或在此发布一个链接!谢谢- – Lee 2011-06-04 16:40:01