tumblr / jumblr

Tumblr API v2 Java Client
Apache License 2.0
278 stars 105 forks source link

how do i get more then 20 Posts from client.blogPosts? #118

Closed phrex1 closed 6 years ago

phrex1 commented 6 years ago

I am using the API to write my own App where i fetch all the Images from a Tumblr Blog. Somehow when i use the client.blogPosts(); function and then iterate through the posts i only get 20 images. I iterate through it this way:

Map<String, Integer> options = new HashMap<String, Integer>();
        options.put("limit", 100);
        options.put("offset", 5);

List<Post> posts = client.blogPosts("random.tumblr.com", options);

 for(Post post2 : posts){

            String type = post2.getType();
            if(type.equals("photo")){
                PhotoPost post = (PhotoPost) post2;
                imageUrls.add(post.getPhotos().get(0).getOriginalSize().getUrl());
            }
        }

The limit can be set below 20 and it works, but it can never be more then 20 how do i fix this?

jasonpenny commented 6 years ago

The API will only return (up to) 20 posts each time it is called.

The Tumblr API supports pagination by specifying an offset. The page size is what the limit represents. The code can load 20 posts, then load the next 20 posts with a call with offset: 20, then load the next 20 posts with a call with offset: 40, etc.