Cannot create new post using Jumblr (Post type remains "null")

272 views
Skip to first unread message

Jerome Mary JB

unread,
May 15, 2015, 5:22:17 PM5/15/15
to tumbl...@googlegroups.com
Greetings everyone,

I'm trying to create a new post on my Tumblr blog using Java and Jumblr.  This is really a "hello world" proof of concept at this stage.

So here is the main piece of code doing the job :

TextPost currentPost;
        try {
            currentPost = myTumblrClient.newPost(myBlogName, TextPost.class);
            currentPost.setTitle("Post Title");
            currentPost.setBody("Contents");
            currentPost.setState("queued");
            currentPost.save();
        } catch (IllegalAccessException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (InstantiationException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

When executing, I get the following error messages :

Exception in thread "main" com.tumblr.jumblr.exceptions.JumblrException: Not Authorized
    at com.tumblr.jumblr.request.RequestBuilder.clear(RequestBuilder.java:151)
    at com.tumblr.jumblr.request.RequestBuilder.postMultipart(RequestBuilder.java:57)
    at com.tumblr.jumblr.JumblrClient.postCreate(JumblrClient.java:370)
    at com.tumblr.jumblr.types.Post.save(Post.java:339)
    at com.tumblr.jumblr.types.SafePost.save(SafePost.java:17)
    at com.tumblr.jumblr.types.TextPost.save(TextPost.java:9)
    at com.myownname.tumblrtool.mycode.run(mycode.java:76)
    at com.myownname.tumblrtool.mycode.main(mycode.java:16)


Line 16 is my main method.
Line 76 is currentPost.save();

Now, I'm pretty much 100% sure it's not a oAuth key issue, as I'm able to, for example, delete tags from already existing posts.

Furthermore, if I do a .getType() on currentPost right before the .save() method call, I see that the status is null !  This is probably the cause of the error, as the type is mandatory according to the Tumblr API documentation, but I do not see how to change this.  The type is supposed to be determined by the object class used when creating the post (I tried using e.g. QuotePost, I get the very same problem).

I have a gut feeling I'm just missing something obvious here.

Can anybody shed some light on this issue ?  Thanks ahead !

J.

Kevin Coughlin

unread,
May 16, 2015, 2:27:56 PM5/16/15
to tumbl...@googlegroups.com
I was able to successfully queue a post using the code below:

final JumblrClient client = new JumblrClient(consumerKey, consumerSecret);
client.setToken(token, tokenSecret);

try {
final TextPost post = client.newPost(blogName
, TextPost.class);
post.setTitle("Post title");
post.setBody("Post contents");
post.setState("queued");
post.save();
} catch (IllegalAccessException | InstantiationException e) {
e.printStackTrace()
;
}

It looks to me like you are not authorized correctly to the blog that you are attempting to post to as reflected by the Not authorized exception thrown. Please make sure that you are setting the correct credentials prior to saving a post with the Jumblr client.

Best,
Kevin

Kevin Coughlin

unread,
May 16, 2015, 2:40:34 PM5/16/15
to tumbl...@googlegroups.com
You are correct that getType on the post object returns null. Jumping through the source it looks like type is hardcoded per post type in a "detail" HashMap that is sent when the post is saved. This doesn't stop the post from being created via the API since it is sent over, but we should be returning the correct value to clients. Ticketed.

Jerome Mary JB

unread,
May 17, 2015, 5:33:37 AM5/17/15
to tumbl...@googlegroups.com
Hello Kevin,

Thanks for your time !

Even using a verbatim copy of your code yields the same error here.

So you must be right, there probably is an authorization problem.

What I do not understand then, is why I'm able to, for example, delete a tag on the last post using this code :

Post lastPost = myBlog.posts().get(0);
        lastPost.removeTag("sometag");
        try {
            lastPost.save();
        } catch (IOException e2) {
        e2.printStackTrace();
        }


How come I can be authorized to delete a tag on an existing post but not save a new post ?

I went to https://www.tumblr.com/oauth/register to get my consumer key and secret, identifying my application.

With the same Tumblr account I then went to https://api.tumblr.com/console/calls/user/info and provided my consumer key and secret in order to authorize the application for my account and obtain the oAuth token and token secret.

The first pair I pass when creating the client.

The second pair I pass using the setToken method.

Is there a method I can call on the client to verify my access rights, or some other way to understand what is going on ?

Best regards,

J.

Kevin Coughlin

unread,
May 17, 2015, 3:20:50 PM5/17/15
to tumbl...@googlegroups.com
You can call client.user() (JavaDoc) to verify that an authorized User model is returned with the blog that you're trying to post to listed as one of its blogs. I just tested again and when my keys are set correctly I am able to post to one of my blogs. When my keys are incorrect / not set I get "Not authorized".

Jerome Mary JB

unread,
May 18, 2015, 5:42:42 AM5/18/15
to tumbl...@googlegroups.com
Hi again, Kevin,

I do just that, calling client.user() and the getting (and siplaying in console) the names of the blog and the user.  And everything looks fine at that point.

As I said I can also get the last post and remove one of its tags, and it works.

So I AM properly authenticated and have a least SOME rights on the blog.

I'm wondering if the way I authorize my application for my account is not the problem.  Maybe the request does not include permission to create a new post but allows for modifying an existing one ?  As I said I went to https://api.tumblr.com/console/calls/user/info to provide my consumer key/secret and get my token key/secret.

I understand that, in a typical use case, the application would be web-based and handle the autorization step online for any visiting user.  I am however just trying to write a few small tools in a Java desktop application (consoel really, a small thing for personnal use).  So I have to handle this in an asynchronous way, but maybe going through the API console is not the right way to do it.

Thx again,

J.

Kevin Coughlin

unread,
May 18, 2015, 8:04:25 AM5/18/15
to tumbl...@googlegroups.com
I was also able to create a new post with my account by hardcoding the auth tokens returned by Tumblr's API console and using the code I shared above. So it should also work for you.

Jerome Mary JB

unread,
May 18, 2015, 8:14:06 AM5/18/15
to tumbl...@googlegroups.com
This is puzzling, because it sounds like we're doing 99% the same thing at this point.
I will try again and share my entire code if you don't mind.  I don't have a lot of time on my hands so don't expect more until Friday.
Thanks for your dedication, it's much appreciated :-)

J.

Jerome Mary JB

unread,
May 18, 2015, 8:16:04 AM5/18/15
to tumbl...@googlegroups.com
Just an idea...  Might this occur if I were using an older version of the Jumblr client JAR ?
I will have to check what exactly I'm using, I'm not at my dev. station right now.

J.

Kevin Coughlin

unread,
May 18, 2015, 8:16:39 AM5/18/15
to tumbl...@googlegroups.com
Can you share the code where you instantiate the client, set the tokens, and attempt to create the post? Remove your credentials before sharing though please. I'll take your snippet and use my keys in an attempt to debug.

Jerome Buyle

unread,
May 18, 2015, 8:21:08 AM5/18/15
to tumbl...@googlegroups.com
Will do this later.  As I said I'm not at my workstation.  I'm not even in the same country at this stage ;-)
--
You received this message because you are subscribed to a topic in the Google Groups "Tumblr API Discussion" group.
To unsubscribe from this group and all its topics, send an email to tumblr-api+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
 
Reply all
Reply to author
Forward
0 new messages