I am trying to post a new text message in tumblr wall from C# Web Application.. But I'm getting the "The remote server returned an error: (401) Unauthorized." error message when i try to post message. I'm using the following url (
http://api.tumblr.com/v2/blog/upfrontApp.tumblr.com/post) to post a text message. The
upfrontApp.tumblr.com is my tumblr application name.. I'm trying fix this error from last two, three weeks but i can not get a correct solution.. Please help me. Please give me any suggestion or idea.. Your any suggestion or idea will be helping me lot.. I'm waiting for your response. Thanks a lot..
this is my code to post a text message..
public string APIWebRequest(string method, string url, string postData)
{
Uri uri = new Uri(url);
string nonce = this.GenerateNonce();
string timeStamp = this.GenerateTimeStamp();
string outUrl, querystring;
string sig = this.GenerateSignature(uri,
this.ConsumerKey,
this.ConsumerSecret,
this.Token,
this.TokenSecret,
method,
timeStamp,
nonce,
out outUrl,
out querystring);
HttpWebRequest webRequest = null;
webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
webRequest.ContentType = "application/x-www-form-urlencoded"; // text/xml
webRequest.Method = method;
webRequest.Credentials = CredentialCache.DefaultCredentials;
webRequest.AllowWriteStreamBuffering = true;
webRequest.PreAuthenticate = true;
webRequest.ServicePoint.Expect100Continue = false;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
webRequest.Headers.Add("Authorization", "OAuth realm=\"
http://api.tumblr.com/\",oauth_consumer_key=\"" + this.ConsumerKey + "\",oauth_token=\"" + this.Token + "\",oauth_signature_method=\"HMAC-SHA1\",oauth_signature=\"" + HttpUtility.UrlEncode(sig) + "\",oauth_timestamp=\"" + timeStamp + "\",oauth_nonce=\"" + nonce + "\",oauth_verifier=\"" + this.Verifier + "\",oauth_version=\"1.0\"");
if (postData != null)
{
byte[] fileToSend = Encoding.UTF8.GetBytes(postData);
webRequest.ContentLength = fileToSend.Length;
Stream reqStream = webRequest.GetRequestStream();
reqStream.Write(fileToSend, 0, fileToSend.Length);
reqStream.Close();
}
string returned = WebResponseGet(webRequest);
return returned;
}