I can't see what I'm doing wrong, but that's probably because it's my first tango with oauth and I'm sure I'm newb-ing it up somewhere. I'm currently using the oauth library hosted by google code and linked on oauth's website (http://oauth.googlecode.com/svn/code/csharp/)
For the following code, the variable "YQL" is an "OAuthBase" object that's declared within the scope of my class as protected like this:
private OAuthBase YQL;
and initialized like this:
public AverageEverydayConstructor()
{
...
YQL = new OAuthBase();
...
}
And here is where all the actual non-functionality occurs (the string "key" is my Consumer Key and "secret" is my Consumer Secret)
private string yahooRetrieveToken(string key, string secret)
{
string tokenRequestUrl = @"https://api.login.yahoo.com/oauth/v2/get_request_token";
string parameters = "";
string timestamp = YQL.GenerateTimeStamp();
string nonce = YQL.GenerateNonce();
parameters += "?oauth_nonce=" + nonce;
parameters += "&oauth_timestamp=" + timestamp;
parameters += "&oauth_consumer_key=" + key;
parameters += "&oauth_signature_method=HMAC-SHA1";
parameters += "&oauth_signature=" + secret;
parameters += "&oauth_version=1.0";
parameters += "&xoauth_lang_pref=en-us";
parameters += "&oauth_callback=\"oob\"";
string fullUrl = tokenRequestUrl + parameters;
Clipboard.SetText(fullUrl);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullUrl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //this is the line that actually err's with 401.
Stream result = response.GetResponseStream();
//And yes, I'm aware I'm not using very good practice and haven't properly closed the stream. I'm just trying to get it to work first, but don't worry I haven't forgotten.
string unparsedResult = result.ToString();
return unparsedResult;
}
I've tried everything I can think of and gone over this page (http://developer.yahoo.com/oauth/guide/oauth-requesttoken.html) dozens of times. To make sure I covered all my bases I've also tried changing the two lines below back and forth just so see if there was any change.
parameters += "&oauth_signature_method=PLAINTEXT";
parameters += "&oauth_signature=" + secret + "%26";
Thanks anyone!