Trying to post on Tumblr (Not Authorized)

133 views
Skip to first unread message

Andreas S

unread,
Mar 9, 2015, 6:56:20 PM3/9/15
to tumbl...@googlegroups.com

I am trying to create a text blog post on Tumblr. When I am running this code, I get the error: "Not Authorized"

I beleive I am passing in the signature in the POST method. I am not good at how this is done so I can't understand what I am doing wrong.

I have used this .cs class which is: "OAuthBasehttps://gist.github.com/tsupo/112124#file-oauthbase-cs


var postUrl = "http://api.tumblr.com/v2/blog/this-is-my-blog-name.tumblr.com/post";
        using (var wc = new WebClient())
        {
            var oauth = new OAuthBase();
            var consumerKey = "1j1j1j1j1j1j1j1j1";
            var consumerSecret = "2j2j2j2j2j2j2j2j";
            var oauthToken = "3j3j3j3j3j3j3j3j3j3";
            var oauthTokenSecret = "4j4j4j4j4j4j4j4j44j";
            var timestamp = oauth.GenerateTimeStamp();
            var nonce = oauth.GenerateNonce();
            string url, url2;
            var values = new System.Collections.Specialized.NameValueCollection();

            //This is the blog post title and text
            values.Add("title", "Title of blog post");
            values.Add("type", "text");
            values.Add("body", "This is the Blog text");

            var postUri = new Uri(postUrl);
            var signature = oauth.GenerateSignature(
                postUri,
                consumerKey,
                consumerSecret,
                oauthToken,
                oauthTokenSecret,
                "POST",
                timestamp,
                nonce,
                null,
                out url,
                out url2);
            var urlEncodedSignature = oauth.UrlEncode(signature);
            var authHeader = "OAuth " + url2 + "&oauth_signature=" + urlEncodedSignature + "\"";
            authHeader = authHeader.Replace("&", "\", ").Replace("=", "=\"");
            wc.Headers.Add("Authorization", authHeader);
            try
            {
                wc.UploadValues(postUri, values);
            }
            catch (WebException webException)
            {
                var message = (new StreamReader(webException.Response.GetResponseStream())).ReadToEnd();
                MessageBox.Show(message.ToString());
            }
        }

Benjamin Tsai

unread,
Apr 8, 2015, 9:24:17 PM4/8/15
to tumbl...@googlegroups.com
Hi Andreas S :

I meet the same problem , so do you find the way to figure this out?

Benjamin Tsai
Reply all
Reply to author
Forward
0 new messages