纠结与Tumblr 的xAuth好几天了,最终发现还是Hammock的rest类库好用,oauth签名什么的都帮你做了
xAuth代码:
Hammock.RestClient restClient = new Hammock.RestClient { Authority = "https://www.tumblr.com/", Credentials = new Hammock.Authentication.OAuth.OAuthCredentials { ConsumerKey = consumerKey, ConsumerSecret = consumerSecret, SignatureMethod = Hammock.Authentication.OAuth.OAuthSignatureMethod.HmacSha1, ParameterHandling = Hammock.Authentication.OAuth.OAuthParameterHandling.HttpAuthorizationHeader, Version = "1.0" } }; restClient.AddHeader("content-type", "application/x-www-form-urlencoded"); Hammock.RestRequest restRequest = new Hammock.RestRequest { Path = "oauth/access_token", Method = Hammock.Web.WebMethod.Post }; restRequest.AddParameter("x_auth_mode", "client_auth"); restRequest.AddParameter("x_auth_username", userName); restRequest.AddParameter("x_auth_password", password); restClient.BeginRequest(restRequest, (request, response, userstate)=> { if (response.StatusCode == HttpStatusCode.OK) { string[] content = response.Content.Split(new char[] { '=', '&' }); OAuth_Token = content[1]; OAuth_Secret = content[3]; callbackSuccess(); } else { callbackFailure(response.StatusCode.ToString() + ": " + response.Content); } }) ;