Skip to main content
The web module represents Instagram media with two classes. PostData is a read-only value object populated from the API response. Post extends it with authenticated methods for liking, commenting, and enumerating users who liked the post.

Package

com.jxinsta.web.endpoints.post

PostData

PostData is the base data class for Instagram media. It is returned directly by PublicAPIs.getPosts and PublicAPIs.getPostInfo, and acts as the superclass of Post.

Fields

id
String
The unique numeric media ID (Instagram’s internal primary key for the post).
shortcode
String
The short alphanumeric code that appears in the post URL, e.g. ABC123 in instagram.com/p/ABC123/.
caption
String
The caption text of the post. May be null if the post has no caption.
mediaType
Post.MEDIA_TYPE
The type of media content. One of IMAGE, VIDEO, or CAROUSEL.
download_url
String[]
Array of direct media URLs. For IMAGE and VIDEO posts the array contains a single entry. For CAROUSEL posts each index corresponds to one slide, in order.
likes
int
The number of likes the post has received.
comments
int
The total number of comments on the post.

Post.MEDIA_TYPE enum

ConstantDescription
IMAGEA single static image.
VIDEOA single video clip.
CAROUSELA multi-item slideshow of images or videos.

Post

Post extends PostData and is returned by JxInsta.getPost. It carries a live session internally and exposes methods that perform actions against the post on Instagram.

like()

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

dislike()

Removes the authenticated user’s like from the post (equivalent to “unliking”).
post.dislike();
Returnsvoid ThrowsInstagramException

likers()

Fetches the usernames of all accounts that have liked the post.
List<String> users = post.likers();
users.forEach(System.out::println);
ReturnsList<String> of usernames. ThrowsInstagramException

getComments()

Returns a CommentPaginator for the post’s comments. Call next() repeatedly until hasNext() returns false.
CommentPaginator pager = post.getComments();
while (pager.hasNext()) {
    pager.next().forEach(c -> System.out.println(c));
}
Returnscom.jxinsta.web.paginators.CommentPaginator

comment(String comment)

Posts a text comment on this post as the authenticated user.
post.comment("Great shot!");
comment
String
required
The text content of the comment to post.
Returnsvoid ThrowsInstagramException