我看不到我做錯了什麼,但這可能是因爲這是我的第一個oauth探戈,我確定我在某處將它新建了。我目前使用由google代碼託管的oauth庫,並鏈接到oauth的網站(http://oauth.googlecode.com/svn/code/csharp/)C#嘗試檢索yahoo oauth請求令牌結果401
對於下面的代碼,變量「YQL」是
private OAuthBase YQL;
像這樣初始化:我班的範圍內聲明的AS保護像這樣的「OAuthBase」對象
public AverageEverydayConstructor()
{
...
YQL = new OAuthBase();
...
}
這裏是所有實際的非功能時(在字符串「鍵」是我的消費者密鑰,「祕密」是我的消費者密碼)
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;
}
我用盡了一切我能想到的走了過來這個頁面(http://developer.yahoo.com/oauth/guide/oauth-requesttoken.html)數十次。爲了確保我覆蓋了所有的基地,我也嘗試過來回改變下面兩行,看看是否有任何改變。
parameters += "&oauth_signature_method=PLAINTEXT";
parameters += "&oauth_signature=" + secret + "%26";
謝謝大家!
它仍然工作!我永遠不會猜測使用oauth_signature_method PLAINTEXT和auth_signature的祕密,謝謝。 – vlscanner