trying to POST Photo but it is not visible on blog

107 views
Skip to first unread message

Rajesh Tiwari

unread,
Nov 6, 2017, 2:00:44 AM11/6/17
to Tumblr API Discussion
Hello Everyone,

We are trying to POST Photo using the below code but getting 200 Ok message but the photo is not visible on the blog, we are tried digging deep but could not find way to work.

            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("d", DateTime.Now.Ticks.ToString());

            var authzHeader = Helper.OAuthHeader(appUrl, "POST", "IdxX6tgxlvsZkwYRwF0nERkMGr1lT7JAUP5imjtjHg5emjyBDR", "IdxX6tgxlvsZkwYRwF0nERkMGr1lT7JAUP5imjtjHg5emjyBDR", parameters);
            
            using (HttpClient client = new HttpClient())
            {
                var datas = new Dictionary<string, string>()
                {
                   {"type","photo"},
                   {"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 = client.PostAsync("/?type=photo&source=http://www.planwallpaper.com/static/cache/32/43/3243c8ee76b24e95e3e406a8bd1f8493.jpg&caption=testphoto", data);
                
                Task.WaitAll(result);
                HttpResponseMessage loHttpResponseMessage = result.Result;
            }

 From this we get the 200 response but the image is not visible on the blog. Can anyone help us.

Thanks and regards.
Raj


Alexander Lozada

unread,
Nov 6, 2017, 6:18:42 PM11/6/17
to Tumblr API Discussion
What language/library are you using for this?

Rajesh Tiwari

unread,
Nov 7, 2017, 5:15:28 AM11/7/17
to Tumblr API Discussion
Hi Alexander,

We use c# language/ library as System.Net.Http.

Thanks and regards.
Raj

Michael Ceyko

unread,
Jan 4, 2018, 2:01:45 PM1/4/18
to Tumblr API Discussion
Hey Raj,

I haven't run your code directly, but I made very similar requests, with the same parameters:

POST /v2/blog/{{blog-identifier}}/post
type=photo
source=http://www.planwallpaper.com/static/cache/32/43/3243c8ee76b24e95e3e406a8bd1f8493.jpg
caption=test+image+api

The created post does indeed contain the image of a house by a lake and the provided caption.

A few things stand out though that you may want to look into:
- You're duplicating data in both the POST body as well as the query string. You should only include it in the POST body, via FormUrlEncodedContent.
- You mention that you're getting a 200 response back, but for a post creation request, it should be a 201, so you might want to make sure you're making the requests you think you are.
- I'm not sure what Helper.OAuthHeader does, but it looks like it's using the same string twice. Maybe one is a key and one is supposed to be a secret?

Best of luck.

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