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