What's the right url when posting?

265 views
Skip to first unread message

Sheldon Han

unread,
Oct 23, 2011, 2:11:12 PM10/23/11
to tumbl...@googlegroups.com
Hi guys,

I can get all good responses except the posting one in API v2. It always gives "Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)"".
I use the url "http://api.tumblr.com/v2/blog/xxxxxx.tumblr.com/post?type=text&body=blahblahblah" and other parameters for oauth connection. Do I make a mistake in the url making? I very appreciate if someone can help me.

BTW, Tumblr does need a better doc for API.

John Bunting

unread,
Oct 23, 2011, 2:41:23 PM10/23/11
to tumbl...@googlegroups.com
Hey,

The url for api.tumblr.com shouldn't contain the type and body of the post you are trying to create.

That information should be in the body of a POST request to http://api.tumblr.com/v2/blog/xxxxxxx.tumblr.com/post

The error you are getting looks like it's from an Objective-C. I'm not really familar with it, but my google-fu is saying that this is because you most likely are unauthorized. Check your headers and everything to make sure that you are completing the OAuth transaction and getting the access tokens that can be used to post to the api.
--
John Bunting

Simplicity is prerequisite for reliability
    --Edsger W. Dijkstra

John Bunting

unread,
Oct 23, 2011, 2:43:02 PM10/23/11
to tumbl...@googlegroups.com
I'm also going to show you a gist I have setup here: https://gist.github.com/1279848

This is the python oauth client, it walks you through the OAuth process as well as shows you how to post to the api with the access tokens.

wyvern

unread,
Oct 23, 2011, 7:56:56 PM10/23/11
to Tumblr API Discussion
Tumblr API doc is suck.

It never say how to send request parameters.

Using query parameter or using body of request??

if using body of request, what content type is it?? application/x-www-
url-encoded?? or multipart/form-data??

I guess Tumblr team has no skills and dont know what kind of
information is needed at least for http application.

On Oct 24, 3:11 am, Sheldon Han <hxd1...@gmail.com> wrote:
> Hi guys,
>
> I can get all good responses except the posting one in API v2. It always
> gives "*Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be
> completed. (NSURLErrorDomain error -1012.)"*".
> I use the url "http://api.tumblr.com/v2/blog/xxxxxx.tumblr.com/post?type=text&body=b..."

Steven Pears

unread,
Oct 24, 2011, 11:57:09 AM10/24/11
to tumbl...@googlegroups.com
I'm getting a very similar issue inside my C# implementation!
 
I've the entire API mapped out and working, except the post URL - which consistently comes back from Tumblr with an unauthorised error message no matter what I try to POST in the body content.
 
The only way I can make it work is by putting the post data into the URL query itself - which is obviously wrong (especially with encoded photos!) but it does then authenticate and I get a successful post response.
 
Any suggestion from the Tumblr team as to what we can check would be really useful.
 
Steven
 

From: coding...@gmail.com
Date: Sun, 23 Oct 2011 14:41:23 -0400
Subject: Re: What's the right url when posting?
To: tumbl...@googlegroups.com

John Bunting

unread,
Oct 24, 2011, 12:04:27 PM10/24/11
to tumbl...@googlegroups.com
Are you urlencoding your body parameters?

Steven Pears

unread,
Oct 24, 2011, 12:16:16 PM10/24/11
to tumbl...@googlegroups.com
I am - yes, but in the simple case of a draft text post it shouldn't matter, my request of:
 
type=text&body=Test&state=draft
 
is sent to http://api.tumblr.com/v2/blog/xxxxx.tumblr.com/post
 
This works if I place the data in the URL - fails in the body.
 
The response is:
 
{"meta":{"status":401,"msg":"Not Authorized"},"response":[]}
 
Steven
 

From: coding...@gmail.com
Date: Mon, 24 Oct 2011 12:04:27 -0400

John Bunting

unread,
Oct 24, 2011, 12:26:43 PM10/24/11
to tumbl...@googlegroups.com
Hmm. Can you post some code? usually that helps people get a better grasp about what's going on.

I just did an api call using the python-oauth lib, and it worked just fine. I did,  as a difference, url encode my body before sending it though.

Steven Pears

unread,
Oct 24, 2011, 12:31:38 PM10/24/11
to tumbl...@googlegroups.com

the sample body I posted was URL-encoded, ASCII text shouldn't appear any different.
 
Do you mean you URL encoded the form-encoding seperators as well?
 
Steven

From: coding...@gmail.com
Date: Mon, 24 Oct 2011 12:26:43 -0400

John Bunting

unread,
Oct 24, 2011, 12:42:08 PM10/24/11
to tumbl...@googlegroups.com
Sorry I should be more explicit.  You need to use application/x-www-form-urlencoding.

The example being:

In [4]: urllib.urlencode({"body": "omg", "type": "text", "state" : "draft", "title": "I'm a little tea pot."})
Out[4]: 'body=omg&state=draft&type=text&title=I%27m+a+little+tea+pot.'

This should be sent over in the POST body.

Sheldon Han

unread,
Oct 24, 2011, 1:31:27 PM10/24/11
to tumbl...@googlegroups.com
Hi JB,

Thanks for replying.

I did finish the OAuth process, because I get successful response for "api.tumblr.com/v2/user/info", which also uses a post method and OAuth.

As your advice, I add the type to http body. But I still get the same error "Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)"".
Here's my code(objetive-c). I use OAuthConsumer framework.

OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.tumblr.com/v2/blog/xxx.tumblr.com/post"

                                                                   consumer:consumer 

                                                                      token:token 

                                                                      realm:nil

                                                          signatureProvider:nil

                                                                      nonce:[self _generateNonce]

                                                                  timestamp:[self _generateTimestamp]];    

    [request setHTTPMethod:@"POST"];

    [request setOAuthParameterName:@"type" withValue:@"text"];

    [request setOAuthParameterName:@"body" withValue:@"blahblahblah"];

OADataFetcher *fetcher = [[OADataFetcher alloc] init];

    [fetcher fetchDataWithRequest:request 

                         delegate:self

                didFinishSelector:@selector(responseTicket:didFinishWithData:)

                  didFailSelector:@selector(responseTicket:didFailWithError:)];


Steven Pears

unread,
Oct 25, 2011, 2:19:51 AM10/25/11
to tumbl...@googlegroups.com

Thanks for this - strangely, using your example data led me to an issue in the encoding process - which now means I have most post types being created. Just got to handle photo encoding and I'm all done!
 
Thanks for all your help :)

From: coding...@gmail.com
Date: Mon, 24 Oct 2011 12:42:08 -0400

Subject: Re: What's the right url when posting?
To: tumbl...@googlegroups.com

Steven Pears

unread,
Oct 25, 2011, 8:37:27 AM10/25/11
to Tumblr API Discussion
John

I've got posting in general working, but I'm now back to the same
problem so many other people have posted on here, that of photo
uploading. We keep being pointed to the python example - something
that few seem to understand or find useful.

Why are we not just able to create multi-part form requests? From both
my own experience and the messages we've seen appear in the group -
this is handled with much more ease by most of the OAuth client
libraries we're looking at, and is a much more common approach to
binary uploads.

The URL encoding route within .NET is actually hindered by the fact
most of the URL encoding functions don't encode when you break the
limit for a URL, throwing you an exception instead - most .NET OAuth
libraries rely on these functions as they're pretty much spot on for
what OAuth requires.

This single issue may mean I have to cancel my app, DashBuddy, from
release - or think about releasing it without photo support due to the
amount of trouble I'm getting trying to get an authenticated request
with a photo in it. It's just a combination of disappointment and
frustration right now.

Steven Pears

Federico Carlos Erostarbe Candamil

unread,
Oct 25, 2011, 8:47:26 AM10/25/11
to tumbl...@googlegroups.com
Hi Sheldon,

how did you managed to work with like/reblog?

I get a 401 / Anauthorized response from my Obj-C code

wyvern

unread,
Oct 26, 2011, 6:07:04 PM10/26/11
to Tumblr API Discussion
If sending parameters in the application/www-form-urlencoded in the
body of request. One big problem come arise when posting photo(binary
values?),
Those parameters has to be included in the process of generating
signature base string of OAuth.

The problem is most OAuth client libarary expects to takes parameters
as *string* or treats them as *string* internally. so when signing
request,
those binary paramaters are handled incorrectly(that is, UTF8 encoding
are applied to those binary parameters incorrectly).

Look at section 3.6. Percent Encoding in RFC5849 http://tools.ietf.org/html/rfc5849.

It says 1. Text values are first encoded as UTF-8 octets per
[RFC3629] if
they are not already. This does not include binary values that
are not intended for human consumption.

This is very ambiguous. which values are text or binary??

anyway, I also give up creating tumblr application without clear
better documentation.

Steven Pears

unread,
Oct 27, 2011, 1:29:13 AM10/27/11
to tumbl...@googlegroups.com
It's not just the OAuth libraries, most APIs understand this distinction too - which is why multi-part form posts are used with file-based API calls; it makes that distinction extremely clear - either it's a value, or it's a file - but the Tumblr API has gone from having this clear distinction to muddying the waters and making it more awkward to understand than it needed to be for developers, but also going against what is considered pretty standard practice.
 
Once the OAuth process has been successful - very few posts seem on here seem to be about the confimed API calls, normally they're missing or desirable functionality - maybe some clarification. That's with the exception of photo posts, surely that's a sign that this is a pain point that needs fixing?
 
 

Sheldon Han

unread,
Oct 28, 2011, 11:56:32 AM10/28/11
to tumbl...@googlegroups.com
Hi guys,

I finally make it work!

Actually, it's simple. Here's the code.

OARequestParameter *parameter1 = [[OARequestParameter allocinitWithName:@"***" value:@"***"];

// add more parameters you need

NSArray *params = [NSArray arrayWithObjects: parameter1, nil];

 [request setParameters:params];


Other code, pls look at my former reply.


Have fun!


Sheldon

mohacs

unread,
Oct 28, 2011, 9:34:29 PM10/28/11
to Tumblr API Discussion
great thank you so much.
Reply all
Reply to author
Forward
0 new messages