Receiving only 20 messages returned through PyTumblr

I use PyTumblr to return all my posts, but it only returns 20. I found kwarg for the posts function, called the limit, but when I set 1000, it still returned 20. Any idea what I'm doing wrong?

CLIENT = pt.TumblrRestClient(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET) all_posts = CLIENT.posts(BLOG_URL, limit=1000) 
+2
source share
1 answer

The Tumblrs API allows you to specify a limit of up to 20. Thus, your limit of 1000 is ignored, and instead you get 20. You will have to use paging in conjunction with the offset parameter.

You can write yourself some kind of generator that, like scrolling endlessly, requests the next page while you keep asking for more messages:

 def getAllPosts (client, blog): offset = 0 while True: posts = client.posts(blog, limit=20, offset=offset) if not posts: return for post in posts: yield post offset += 20 
+3
source

Source: https://habr.com/ru/post/1273405/


All Articles