Jumblr API gives bad request while posting image t

2019-06-24 08:37发布

What I have

I have an image File object trying to post to Tumblr using Jumblr API

My problem

When I try to post the image I get com.tumblr.jumblr.exceptions.JumblrException: Bad Request Response code :400

My code

client = new JumblrClient(CONSUMER_KEY,SECRET_KEY);
                            client.setToken(TOKEN, TOKEN_SECRET);
                            User user=client.user();
                            userName=user.getName();

                            PhotoPost photoPost=client.newPost(client.user().getBlogs().get(0).getName(),PhotoPost.class);
                            photoPost.setCaption("My Tumblr post");


                            photoPost.setPhoto(new Photo(Methods.FILE_IMAGE));
                            photoPost.save();

2条回答
我命由我不由天
2楼-- · 2019-06-24 08:56

I had a similar problem posting a video & audio. However, posting an Image worked like a charm..

JumblrClient client = new JumblrClient(
                CONSUMER_KEY,
                SECRET_KEY
        );
client.setToken(
                TOKEN,
                TOKEN_SECRET
        );
PhotoPost post = client.newPost(strBlogName, PhotoPost.class);
post.setCaption("This is my caption");
post.setData(new File(fileUri.getPath()));
post.save(); //Initiates upload of image file
查看更多
Root(大扎)
3楼-- · 2019-06-24 08:57

I've encountered the same issue using Jumblr.

Instead of this method (does it somehow trigger Android gallery? Couldn't find any javadoc for Methods.FILE_IMAGE)

photoPost.setPhoto(new Photo(Methods.FILE_IMAGE));

I suggest you to try any flavor of

photoPost.setData(new File(fileName)); //if it's possible on Android

And please try it with different files: Tumblr has not only file-size limitations, but also some weird check for file being valid. ~3% of gif files I upload throw Bad Request Response code :400. Those files are not exceeding GIF size limit and they're displayed fine on my machine, but Tumblr, for some reason rejects them, so please try post.setData and try it with some bulletproof-valid file, because from the rest of your code - it definitely looks like you're doing it right

查看更多
登录 后发表回答