JxInsta models all paginated API responses as standard Java Iterator implementations. Each paginator class holds internal cursor state so you do not need to track pagination tokens manually. Call hasNext() before each call to next() — when hasNext() returns false the API has confirmed there are no further pages. Calling next() after that point throws NoSuchElementException.
All paginators are obtained from other API objects rather than being constructed directly. The table below shows where to get each one.
| Paginator | How to obtain | Module |
|---|
FeedPaginator | Mobile: JxInsta.getFeed() / Web: JxInsta.getFeedPosts(cursor) | Mobile + Web |
PostPaginator | Profile.getPosts() (Mobile) / Profile.getPosts(cursor) (Web) | Mobile + Web |
ProfilePaginator | Profile.getFollowers() / Profile.getFollowings() | Mobile + Web |
CommentPaginator | Post.getComments() | Mobile + Web |
MessagePaginator | Thread.getMessages() | Mobile |
HashtagPaginator | PublicAPIs.hashtagSearch(tag, after) | Web |
FeedPaginator
FeedPaginator pages through the authenticated user’s home feed timeline, fetching a batch of posts on each call to next(). Both modules provide a feed paginator but through different methods.
Packages:
- Mobile:
com.jxinsta.mobile.paginators.FeedPaginator — obtained via JxInsta.getFeed()
- Web:
com.jxinsta.web.paginators.FeedPaginator — obtained via JxInsta.getFeedPosts(String cursor)
Implements: Iterator<List<Post>>
Methods
| Method | Return type | Description |
|---|
hasNext() | boolean | true while the API indicates more pages are available (more_available in the API response). |
next() | List<Post> | Fetches the next page of feed posts. Throws NoSuchElementException if hasNext() is false. |
Example
// Mobile module
FeedPaginator paginator = insta.getFeed();
while (paginator.hasNext()) {
List<Post> posts = paginator.next();
for (Post post : posts) {
System.out.println(post.shortcode + " — " + post.likes + " likes");
}
}
// Web module
FeedPaginator paginator = client.getFeedPosts(null);
while (paginator.hasNext()) {
List<Post> posts = paginator.next();
for (Post post : posts) {
System.out.println(post.shortcode + " — " + post.likes + " likes");
}
}
PostPaginator
PostPaginator pages through the posts published by a specific user profile, returning 12 posts per page. Available in both modules.
Packages:
- Mobile:
com.jxinsta.mobile.paginators.PostPaginator
- Web:
com.jxinsta.web.paginators.PostPaginator
Implements: Iterator<List<Post>>
Methods
| Method | Return type | Description |
|---|
hasNext() | boolean | true while the API returns a next_max_id cursor, indicating further posts exist. |
next() | List<Post> | Fetches the next 12 posts for the profile. Throws NoSuchElementException when exhausted. |
Example
Profile profile = client.getProfile("natgeo");
PostPaginator paginator = profile.getPosts(null);
while (paginator.hasNext()) {
paginator.next().forEach(p -> System.out.println(p.id));
}
ProfilePaginator
ProfilePaginator is used for both followers and followings lists. It fetches up to 200 accounts per page (Mobile) or 50 per page (Web) and is returned by both Profile.getFollowers and Profile.getFollowings.
Packages:
- Mobile:
com.jxinsta.mobile.paginators.ProfilePaginator
- Web:
com.jxinsta.web.paginators.ProfilePaginator
Implements: Iterator<List<Profile>>
Methods
| Method | Return type | Description |
|---|
hasNext() | boolean | true while there is a next_max_id cursor and the most recent page was non-empty. |
next() | List<Profile> | Fetches the next page of follower or following accounts. Each entry is a full Profile object. |
Example
Profile profile = client.getProfile("instagram");
// Iterate followers
ProfilePaginator followers = profile.getFollowers(null);
while (followers.hasNext()) {
followers.next().forEach(f -> System.out.println(f.username));
}
// Iterate followings
ProfilePaginator following = profile.getFollowings(null);
while (following.hasNext()) {
following.next().forEach(f -> System.out.println(f.username));
}
CommentPaginator pages through the comments on a single post. Obtain it via Post.getComments(). Available in both modules.
Packages:
- Mobile:
com.jxinsta.mobile.paginators.CommentPaginator
- Web:
com.jxinsta.web.paginators.CommentPaginator
Implements: Iterator<List<Comment>>
Fields
| Field | Type | Description |
|---|
cursor | String | Public cursor field. Holds the current next_min_id value between next() calls. |
Methods
| Method | Return type | Description |
|---|
hasNext() | boolean | true while the API returns a next_min_id cursor. |
next() | List<Comment> | Fetches the next batch of comments. Throws NoSuchElementException when all comments are loaded. |
Example
Post post = client.getPost("https://www.instagram.com/p/ABC123/");
CommentPaginator pager = post.getComments();
while (pager.hasNext()) {
pager.next().forEach(c -> System.out.println(c));
}
MessagePaginator
MessagePaginator pages through the messages in a direct message thread, loading 20 messages per page in reverse-chronological order (oldest first when paginating with the older direction).
Package: com.jxinsta.mobile.paginators.MessagePaginator
Implements: Iterator<List<com.jxinsta.mobile.endpoints.direct.Message>>
MessagePaginator is part of the mobile module and requires a mobile client session (auth token), not a web session ID.
Methods
| Method | Return type | Description |
|---|
hasNext() | boolean | true while the thread object contains a non-null, non-empty oldest_cursor. |
next() | List<Message> | Fetches the next 20 messages. Returns an empty list if the thread has no items. |
Example
// Obtain via Thread.getMessages() on a thread from the inbox
Inbox inbox = insta.getDirectInbox(10, 5);
Thread thread = inbox.threads.get(0);
MessagePaginator pager = thread.getMessages();
while (pager.hasNext()) {
List<Message> messages = pager.next();
messages.forEach(m -> System.out.println(m));
}
HashtagPaginator
HashtagPaginator pages through posts associated with a hashtag using the public GraphQL endpoint. It does not require authentication. Each page contains up to 29 HashtagPost records.
Package: com.jxinsta.web.paginators.HashtagPaginator
Implements: Iterator<List<com.jxinsta.web.endpoints.HashtagPost>>
Methods
| Method | Return type | Description |
|---|
hasNext() | boolean | true while the API response includes "has_next_page": true in the page info. |
next() | List<HashtagPost> | Fetches the next page of hashtag posts. Throws NoSuchElementException when exhausted; wraps InstagramException in RuntimeException on API errors. |
Example
HashtagPaginator pager = PublicAPIs.hashtagSearch("photography", null);
while (pager.hasNext()) {
List<HashtagPost> posts = pager.next();
posts.forEach(hp ->
System.out.println("@" + hp.username() + " — " + hp.shortcode())
);
}