Skip to main content
The Post class wraps an individual Instagram media item and exposes both its metadata and interactive methods. You can retrieve a post from a URL, inspect its fields, interact with it (like, comment, fetch likers), paginate its comments, and also upload a new photo to your own account. The Mobile and Web clients share the same public API surface for posts with minor construction differences.

Fetching a post by URL

Pass a standard Instagram post URL to getPost(). The method extracts the shortcode, resolves the media ID, and returns a Post instance with all PostData fields populated.
JxInsta insta = new JxInsta("your_username", "your_password");

Post post = insta.getPost("https://www.instagram.com/p/ABC123xyz/");

Reading PostData fields

Post extends PostData, so all metadata is accessible directly on the returned instance.
System.out.println(post.id);           // numeric media ID
System.out.println(post.shortcode);    // e.g. "ABC123xyz"
System.out.println(post.caption);      // post caption text
System.out.println(post.likes);        // like count
System.out.println(post.comments);     // comment count
System.out.println(post.mediaType);    // MEDIA_TYPE.IMAGE / VIDEO / CAROUSEL
System.out.println(Arrays.toString(post.download_url)); // direct media URL(s)
For CAROUSEL posts, download_url contains one entry per slide. For IMAGE and VIDEO posts it contains a single element.

Media types

The Post.MEDIA_TYPE enum describes the kind of media in the post.
ValueDescription
IMAGEA single photo.
VIDEOA single video (Reel or regular video post).
CAROUSELA multi-item slideshow (album).
if (post.mediaType == Post.MEDIA_TYPE.CAROUSEL) {
    for (String url : post.download_url) {
        System.out.println("Slide URL: " + url);
    }
} else {
    System.out.println("Media URL: " + post.download_url[0]);
}

Liking and disliking

like() sends a like as the authenticated account. dislike() removes an existing like.
post.like();    // add a like
post.dislike(); // remove the like
Both methods throw InstagramException if the request fails.

Adding a comment

Pass the comment text to comment(). The text is posted as the authenticated account.
post.comment("Great shot!");
Instagram may rate-limit or flag accounts that comment at high frequency. Avoid looping over many posts with comment() calls in rapid succession.

Listing likers

likers() returns a List<String> of usernames who have liked the post.
List<String> likers = post.likers();
for (String username : likers) {
    System.out.println(username);
}
Instagram only returns a subset of likers for posts with very high engagement. The list may not be exhaustive on viral content.

Paginating comments

getComments() returns a CommentPaginator which implements Iterator<List<Comment>>. Iterate using hasNext() and next() to retrieve all comment pages.
CommentPaginator commentPages = post.getComments();

while (commentPages.hasNext()) {
    List<Comment> page = commentPages.next();
    for (Comment comment : page) {
        System.out.println(comment);
    }
}
The paginator fetches up to 20 comments per page and advances automatically using an internal cursor.

Uploading a new post

postPicture() is called on the JxInsta client (not on a Post object). It uploads an image from an InputStream and publishes it to the authenticated account’s feed.
InputStream image = new FileInputStream("/path/to/photo.jpg");

insta.postPicture(
    image,
    "Captured this today.",
    false  // set to true to disable likes and comments
);
The third argument, disableLikenComment, maps to Instagram’s comments_disabled and like_and_view_counts_disabled flags. Pass true to publish the post with both interactions turned off.
The image must be a JPEG. Instagram rejects other formats at the upload stage. Convert the image before creating the InputStream.

PostData field reference

FieldTypeDescription
idStringThe numeric media ID (primary key).
shortcodeStringThe alphanumeric code that appears in the post URL after /p/.
captionStringThe caption text. May be null for posts with no caption.
likesintThe number of likes.
commentsintThe number of comments.
mediaTypePost.MEDIA_TYPEThe type of media: IMAGE, VIDEO, or CAROUSEL.
download_urlString[]Direct URL(s) to the media. Multiple entries for CAROUSEL posts.