Avatar of Feivi99
Feivi99

asked on 

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

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(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;

}

here is my GenerateSignature method in oAuthBase class:

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);

}


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
.NET ProgrammingC#

Avatar of undefined
Last Comment
Feivi99
Avatar of dj_alik
dj_alik

try to set
objRequest.Credentials = new NetworkCredential("myLogin", "myPwd");
Avatar of Feivi99
Feivi99

ASKER

dj alik,

I'm not sure what you're referring to. Accessing the Yahoo BOSS api doesnt involve a login or password, all that is needed is to send the correct oauth signature and info, and then the api should respond with the requested information.

I just can't get it to work.
ASKER CERTIFIED SOLUTION
Avatar of dj_alik
dj_alik

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Feivi99
Feivi99

ASKER

I had to dig through some of the links and play around with the code, but in the end it helped.
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo