Working on a React project that involves scraping my Tumlbr blog for photo posts to display on a 'blog' page. Since the tumblr.js package doesn't support in-browser calls and my backend is in Rails, I'm utilizing ajax to accomplish this task. Below is the code snippet I used to fetch the first 20 posts from page 1 of my tumblr:
export const getPosts = () => {
return (dispatch) => {
$.ajax({
url:"https://api.tumblr.com/v2/blog/somewhatadrift.tumblr.com/posts/photo?...&api_key=...",
type: "GET",
context: this,
success: function(result) {
let posts = result.response.posts.filter(post => post.type === 'photo');
dispatch(setPosts(posts));
}
});
}
}
The output of this call can be viewed here.
In the Tumlbr API documentation, it mentions that total_posts represents "The total number of posts available for this request, useful for paginating through results," but does not provide a clear example on how to implement pagination.