Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhotoPost by source url don't get saved in "queued" state #89

Closed
Tickeldi opened this issue Feb 19, 2016 · 12 comments
Closed

PhotoPost by source url don't get saved in "queued" state #89

Tickeldi opened this issue Feb 19, 2016 · 12 comments
Labels

Comments

@Tickeldi
Copy link

Hey. I am not sure what I am doing wrong here. Everything works fine except that my posts are getting saved in a published state instead of queued. No exceptions are thrown.

This is my method.

public void postImage(String imageSource, String text) throws IOException {
  try {
            PhotoPost post = clientToPostWith.newPost(
                    blogname, 
                    PhotoPost.class);
            post.setCaption(text);
            post.setState("queued");
            post.setPhoto(new Photo(imageSource));
            post.save();
            System.out.println(post.getState());
            System.out.println(clientToPostWith.blogPost(blogname, post.getId()).getState());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
    }
}

The output is:

queued
published
@Tickeldi
Copy link
Author

setState("draft")
and
setState("private")
and of course
setState("published")

do what they should do. The posts end up being a draft, private or published but never queued which, coincidentally, is the only state I am interested in :(

@ericleong ericleong added the bug label Feb 21, 2016
@Tickeldi Tickeldi changed the title PhotoPost by source url don't get saved in correct state PhotoPost by source url don't get saved in "queued" state Feb 21, 2016
@Linus12
Copy link

Linus12 commented Feb 21, 2016

Interesting. I do pretty much the same and it works fine for me. In fact when testing, I post to the queue, then in "production" I post to "published". There are a few differences though. I just reviewed where I create the post and I use:

PhotosetPost psp = jClient.newPost(blogname, PhotosetPost.class);

The only difference, supposedly, between PhotoPost and a PhotosetPost is that with a PhotosetPost you can post more than one photo. But the differences in the classes is that Photoset just extends the PhotoPost with three additional interfaces: addPhoto, addSource, addData.

In my case the PhotosetPost is surrounded by a try/catch but I catch all exceptions, i.e.:

PhotosetPost psp;
try {
    psp = jClient.newPost(blogname, PhotosetPost.class);
 } catch (Exception e){
  ...

and the save is surrounded by the try catch as follows:

try {
    psp.save();
} catch (IOException e) {
    ...
}
catch (JumblrException j) {
    ...
}

in my case though this is done because the creation and adding of fields and the final saving is done in different parts of the code.

it shouldn't make any difference, but does it work with a PhotosetPost?

@Tickeldi
Copy link
Author

The location of the catches shouldn't make a difference really as there weren't any exceptions thrown so far but you said so yourself. :)

I tried your suggestion but sadly, the symptoms remain the same. Any post where the state is set to "queue" goes online as "published".

Here is the code at the moment with your suggestion:

    public Poster() {
        clientToPostWith = new JumblrClient(CONSUMER_KEY, CONSUMER_SECRET);
        clientToPostWith.setToken(OAUTH_TOKEN, OAUTH_TOKEN_SECRET);

        blogname = clientToPostWith.user().getName();
    }

    public void postImage(String imageSource, String text) throws IOException {
        try {
            PhotosetPost post = clientToPostWith.newPost(
                    blogname, 
                    PhotosetPost.class);
            post.setCaption(text);
            post.setState("queued");
            post.addSource(imageSource);
            post.save();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
    }

I included the constructor in case I do something wrong there. But authentication, connection etc doesn't seem to be an issue. It is really curious.

@Linus12
Copy link

Linus12 commented Feb 21, 2016

OK, Just a really, really stupid, non technical, question here. How many entries do you currently have in your Tumblr Queue?

@Tickeldi
Copy link
Author

47 which I pushed over there by hand from my drafts

@Tickeldi
Copy link
Author

@Linus12 can I ask you, what version of Java you are using? And I assume you're using jumblr release 0.11?

@Linus12
Copy link

Linus12 commented Feb 22, 2016

@Tickeldi currently using Java version: 1.8.0_73
As for Jumblr, I pulled down the current master source, which includes 0.11 plus a few additional fixes (like #80 and it's duplicate #79). I then made the changes as specified in my three pull requests (#71, #74, and #85). I then compile it into a .jar file that I use on my projects. Hopefully, sometime soon, version 12 will be released with at least these changes in it and I won't have to do this anymore.

But changes I made shouldn't have any affect on the state of a post.

I should also add that my current builds use org.scribe version 1.3.5 (current build is 1.3.7)
and gson version 2.3.1 (current build is 2.6.1)

I downloaded these when I started my first project and haven't updated them since. (Maybe I should?)

Have you tried debugging and verifying a) the actual state just prior to the save, as well as the return response from the save? I had to do this to figure out some obscure error/warning messages that were never returned by Jumblr (or were so obfuscated that the actual error was "lost in translation").

@Tickeldi
Copy link
Author

I'm using java version "1.8.0_74" on linux. I'm also using gson 2.5 but this shouldn't have an influence on jumblr really.
I tried debugging this yes and as far as I can follow the code the request is built just fine with "state=queued". I don't really understand the oauth step where the request gets translated into some kind of bytecode but I can't imagine that any of this contains the reason for the strange behaviour I am experiencing (can't be sure though). The response of a try run I just made was {"meta":{"status":201,"msg":"Created"},"response":{"id":139820754791}}. What I'll do right now is creating a minimal project containing just my problem with hardcoded values (not the token and secrets but everything else) and upload it to github. If that yields another result I'll have to have a look at my setup. If it doesn't maybe you or someone else can try to run it as well and see what happens.

@Tickeldi
Copy link
Author

Here. https://github.com/Tickeldi/jumblrError. Libraries are included.
One class, one method, a main in Poster.java. It will create a post, write the local and remote state of it to stdout and delete the post again.
For me the output is

Lokal state: queued
Remote state: published

@bdenney
Copy link
Contributor

bdenney commented Mar 6, 2016

Can you try setting the state to queue instead of queued?

According to the API docs for the state field:

The state of the post. Specify one of the following: published, draft, queue, private

@Tickeldi
Copy link
Author

Tickeldi commented Mar 6, 2016

Thanks. I feel like an idiot. Firstly, I oriented myself at the actual tumblr api, thinking that the states would be the same here:

States are published, queued, draft and private

And I did not look closely enough at the api-docs. Also I am sure I tried this before and it didn't work. Maybe I did something else wrong at that time because NOW it WORKS.

THANK YOU

@Tickeldi Tickeldi closed this as completed Mar 6, 2016
@bdenney
Copy link
Contributor

bdenney commented Mar 7, 2016

No worries, I'm glad it works for you now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants