Hello,
I've been trying to create a simple search page using the Yahoo BOSS v2 api, but cant get OAuth to work properly. I have all the keys etc, and downloaded a C# class for OAuth at
http://oauth.googlecode.com/svn/code/csharp/OAuthBase.cs , but I keep getting errors.
We've tried the following:
a javascript function builds a yahoo boss query string and then leads to
PageMethods.getYahoo(query
string, responseFunction);
Here's the code behind
[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(ur
i, "<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.G
etResponse
Stream()))
{
result = sr.ReadToEnd();
sr.Close();
}
return result;
}
here is my GenerateSignature method in oAuthBase class:
public string GenerateSignature(Uri url, string consumerKey, string
consumerSecret, out string normalizedUrl, out string
normalizedRequestParameter
s)
{
normalizedUrl = null;
normalizedRequestParameter
s = null;
string signatureBase = GenerateSignatureBase(url,
consumerKey,null
,null,null,GenerateTimeSta
mp(),Gener
ateNonce()
, HMACSHA1SignatureType, out
normalizedUrl, out normalizedRequestParameter
s);
HMACSHA1 hmacsha1 = new HMACSHA1();
hmacsha1.Key = Encoding.ASCII.GetBytes(st
ring.Forma
t("{0}&{1}
",
UrlEncode(consumerSecret),
""));
return GenerateSignatureUsingHash
(signature
Base, hmacsha1);
}
But we keep getting the error:
Message: Sys.Net.WebServiceFailedEx
ception: 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
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.