Skip to main content
PostData is the data carrier populated from the Instagram mobile API JSON for a single media item. Post extends PostData, adds an auth token, and exposes action methods — liking, disliking, commenting, retrieving likers, and paginating comments. You obtain a Post from JxInsta.getPost(url) or via a FeedPaginator. The Post.MEDIA_TYPE enum identifies whether the item is an image, video, or carousel album.

Post.MEDIA_TYPE enum

The MEDIA_TYPE enum reflects the media_type integer returned by the mobile API. It is stored in PostData.mediaType.
ConstantAPI valueDescription
IMAGE1A single still image post.
VIDEO2A video or Reel post.
CAROUSEL8A carousel album containing multiple images or videos.
Post.java
Post post = client.getPost("https://www.instagram.com/p/ABC123xyz/");
if (post.mediaType == Post.MEDIA_TYPE.CAROUSEL) {
    System.out.println("Carousel with " + post.download_url.length + " items");
}

PostData fields

PostData is populated by the PostData(JSONObject postData) constructor, which parses the raw API response.
id
String
The numeric media ID, resolved from pk or id in the API response. Used as the identifier for all action endpoints.
shortcode
String
The URL-safe shortcode for the post, sourced from the code field. Appears in the post URL as /p/<shortcode>/.
mediaType
Post.MEDIA_TYPE
The media type of the post — one of IMAGE, VIDEO, or CAROUSEL. Determined by mapping the integer media_type field in the API response.
caption
String
The post caption text, sourced from caption.text in the API response. null if no caption was set.
likes
int
The current like count for the post, sourced from like_count.
comments
int
The total comment count for the post, sourced from comment_count.
download_url
String[]
An array of direct image/video URLs for download. Contains one element for IMAGE posts (the highest-resolution candidate from image_versions2), and one element per slide for CAROUSEL posts. null for VIDEO posts that do not expose image_versions2.

Static method

Post.getPost(String url)

A static convenience method that fetches post data using the public GraphQL endpoint, without requiring a mobile auth token. Suitable for reading public post metadata from unauthenticated contexts.
Post.java
PostData data = Post.getPost("https://www.instagram.com/p/ABC123xyz/");
System.out.println(data.caption);
System.out.println(data.likes);
url
string
required
The full URL of the Instagram post. The shortcode is extracted from the /p/<shortcode>/ segment and used in the GraphQL variables payload.
ReturnsPostData ThrowsInstagramException

Post fields

In addition to all PostData fields, Post exposes:
hasMore
boolean
Indicates whether additional pages are available in a paginatable context (e.g., when iterating a feed). Set externally by paginators.

Post methods

All methods below require the auth token bound at construction time.

like()

Sends a like on the post on behalf of the authenticated user.
Post.java
Post post = client.getPost("https://www.instagram.com/p/ABC123xyz/");
post.like();
Returnsvoid ThrowsInstagramException

dislike()

Removes a previously placed like from the post.
Post.java
post.dislike();
Returnsvoid ThrowsInstagramException

comment(String comment)

Posts a comment on this media item.
Post.java
post.comment("Great shot!");
comment
string
required
The comment text to post. Must not be null (@NotNull). Sent as the comment_text field in the request body.
Returnsvoid ThrowsInstagramException

likers()

Fetches the list of usernames of accounts that have liked this post.
Post.java
List<String> likers = post.likers();
for (String username : likers) {
    System.out.println(username);
}
ReturnsList<String> — a list of usernames of accounts that liked the post. ThrowsInstagramException

getComments()

Returns a CommentPaginator for lazily iterating through comments on this post. No network request is made until the paginator is advanced.
Post.java
CommentPaginator comments = post.getComments();
while (comments.hasNext()) {
    List<Comment> page = comments.next();
    for (Comment comment : page) {
        System.out.println(comment);
    }
}
ReturnsCommentPaginator

toString()

Returns a human-readable representation of the key post fields for logging and debugging.
Post.java
System.out.println(post.toString());
// Post{id='1234567890', shortcode='ABC123xyz', download_url='[https://...]', caption='...', likes=42, comments=7}