How to post the image and text in tumblr from api i am using ASpnet Core

69 views
Skip to first unread message

Nahush Shrestha

unread,
Apr 25, 2017, 7:34:47 AM4/25/17
to Tumblr API Discussion
i am able to post the image and text from postman but i not able to post from Code.
i am able to get the access_token from user. Here is my code look like


            var authzHeader = oauth.GenerateAuthzHeader(appUrl, "POST");
          
            using (HttpClient client = new HttpClient())
            {
                var datas = new Dictionary<string, string>()
                {
                   {"type","photo"},
                   {"source","IMAGEURL"},
                  {"caption","test image api"}
                };
                var data = new FormUrlEncodedContent(datas);

                client.BaseAddress = new Uri(appUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Add("Authorization", authzHeader);

                var Result = await client.PostAsync("", data); /// from this i get the 401 response
                var result=await.client.PostAsync("/?type=photo&source=https://68.media.tumblr.com/fb7e7302e3f34cd6b4e11229ba3fcf5d/tumblr_o8b1oyML9H1riowtoo1_500.jpg&caption=test photo")/// from this i get the 200 response 
          
}
}

what i am doing wrong.



Michael Ceyko

unread,
Jul 6, 2017, 11:33:04 AM7/6/17
to Tumblr API Discussion
Hi Nahush,

I'm sure you've already figured this out, since it's been a long time. But here's what I was thinking, in case anyone else runs into the issue:

For an OAuth-signed request that has a Content-Type of x-www-form-urlencoded, you must include both the query and the body parameters in the signature. From your code sample, it looks like only the query (via `appUri`) is being included in the signature. I'm not sure how your OAuth library functions exactly, but you'll probably need call it with both `appUri` and `data` to generate the Authorization header.

Regards,
Mike Ceyko
Reply all
Reply to author
Forward
0 new messages