Skip to main content
JxInsta is the primary entry point for the web module. It handles authentication, session management, and account-level actions such as posting media and searching for users. Every authenticated operation in the web module flows through an instance of this class.

Package

com.jxinsta.web.JxInsta

Public fields

username
String
The username of the authenticated account.
password
String
The password of the account. Only populated when the instance was created via the JxInsta(username, password) constructor; null when created via getInstance.
session
String
The sessionid cookie value used to authenticate every request.
crsf
String
The CSRF token attached to state-changing requests.

Constructor

JxInsta(String username, String password)

Logs into Instagram with the supplied credentials, performs the full browser-style login flow, and stores the resulting sessionid and CSRF token on the instance.
JxInsta client = new JxInsta("my_username", "my_password");
System.out.println("Session: " + client.session);
Parameters
username
String
required
The Instagram username of the account to log into.
password
String
required
The plaintext password for the account. The library encodes it in the #PWD_INSTAGRAM_BROWSER format before sending.
Throws
  • java.io.IOException — if a network error occurs while making the login request.
  • InstagramException — if Instagram rejects the credentials or returns an unexpected response. Check getReason() for the specific failure category (e.g., INCORRECT_PASSWORD, CHECKPOINT_REQUIRED, TWO_FACTOR_REQUIRED).

Static factory

getInstance(String session, String crsf)

Creates a JxInsta instance from an existing, already-authenticated session. Use this to avoid logging in on every application start by persisting session and crsf between runs.
JxInsta client = JxInsta.getInstance("sessionid_cookie_value", "csrf_token_value");
session
String
required
A valid sessionid cookie value obtained from a previous login or from the browser’s developer tools.
crsf
String
required
The CSRF token that pairs with the session.
Returns — a new JxInsta instance ready to make authenticated requests.

Methods

getProfile(String username)

Fetches the public and private profile information for any Instagram user by username. Returns a Profile object that also exposes action methods such as follow, block, and getPosts.
Profile profile = client.getProfile("instagram");
System.out.println(profile.name + " — followers: " + profile.followers);
username
String
required
The Instagram username of the account to look up (without the @ symbol).
Returnscom.jxinsta.web.endpoints.profile.Profile ThrowsInstagramException

getFeedPosts(String cursor)

Returns a FeedPaginator that pages through the authenticated user’s home feed. Call next() to retrieve each batch of posts and hasNext() to check whether more pages remain.
FeedPaginator paginator = client.getFeedPosts(null);
while (paginator.hasNext()) {
    List<Post> posts = paginator.next();
    posts.forEach(p -> System.out.println(p.shortcode));
}
cursor
String
Pagination cursor from a previous call. Pass null to start from the beginning of the feed.
Returnscom.jxinsta.web.paginators.FeedPaginator

getFeedStories()

Fetches all active stories visible in the authenticated user’s story tray. The return value is a list of arrays; each inner array holds all story frames for a single account.
List<Story[]> stories = client.getFeedStories();
for (Story[] userStories : stories) {
    for (Story s : userStories) {
        System.out.println(s);
    }
}
ReturnsList<Story[]> ThrowsInstagramException

postPicture(InputStream inputStream, String caption, boolean disableLikeAndComment)

Uploads a JPEG image and publishes it as a new Instagram post on the authenticated account.
try (InputStream is = new FileInputStream("photo.jpg")) {
    client.postPicture(is, "Hello from JxInsta!", false);
}
inputStream
InputStream
required
A readable stream of the image data to upload.
caption
String
required
The caption text for the new post.
disableLikeAndComment
boolean
required
When true, likes and comments are disabled on the new post. Equivalent to toggling “Turn off commenting” in the app.
Returnsvoid Throwsjava.io.IOException, InstagramException

getPost(String url)

Resolves a post URL to a Post object. Internally extracts the shortcode from the URL, converts it to a numeric media ID, and fetches full post data.
Post post = client.getPost("https://www.instagram.com/p/ABC123/");
System.out.println(post.caption);
post.like();
url
String
required
The full URL of the Instagram post, e.g. https://www.instagram.com/p/CODE/.
Returnscom.jxinsta.web.endpoints.post.Post ThrowsInstagramException

search(String username)

Searches Instagram for accounts whose usernames start with the given query string. Returns a map of username → profile picture URL for display in autocomplete or search UIs.
Map<String, String> results = client.search("nat");
results.forEach((user, pic) -> System.out.println(user + " -> " + pic));
username
String
required
The username prefix to search for.
ReturnsMap<String, String> where each key is a username and each value is that user’s profile picture URL. ThrowsInstagramException