troubleshooting Question

Can't implement Yahoo BOSS v2 with OAuth in .net/C#

Avatar of Feivi99
Feivi99 asked on
.NET ProgrammingC#
4 Comments1 Solution1170 ViewsLast Modified:

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 , 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

public static string getYahoo(string url)
String result;
OAuthBase oauth = new OAuthBase();
Uri uri = new Uri("");
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();

return result;


here is my GenerateSignature method in oAuthBase class:

public string GenerateSignature(Uri url, string consumerKey, string
consumerSecret, out string normalizedUrl, out string
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);


But we keep getting the error:

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
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros