Skip to main content
JxInsta is the entry point for every interaction with the Instagram mobile API. Obtain an instance either by authenticating with a username and password, or by supplying an existing mobile auth token via getInstance. Once you have an instance you can fetch profiles, paginate the feed, post pictures, retrieve posts by URL, search for users, and open the direct message inbox.

Constructor

JxInsta(String username, String password)

Authenticates with Instagram using account credentials. On success the instance stores the auth token returned by the mobile API in this.token. Throws InstagramException if the password is wrong, two-factor authentication is required, or any other API-level error occurs.
JxInsta.java
try {
    JxInsta client = new JxInsta("my_username", "my_password");
    System.out.println("Token: " + client.token);
} catch (InstagramException e) {
    System.err.println("Login failed: " + e.getMessage());
} catch (IOException e) {
    System.err.println("Network error: " + e.getMessage());
}
username
string
required
The Instagram account username.
password
string
required
The account password. The library encrypts it before transmission using the #PWD_INSTAGRAM_BROWSER:0:<timestamp>:<password> scheme.
Throws
ExceptionReason
IOExceptionA network or I/O error occurred before receiving a response.
InstagramExceptionAuthentication failed. Check InstagramException.Reasons for the specific cause (INCORRECT_PASSWORD, TWO_FACTOR_REQUIRED, UNKNOWN_LOGIN_ERROR).

Static factory

getInstance(String auth)

Creates a JxInsta instance from an existing mobile auth token, skipping the login round-trip. Use this when you have stored a token from a previous session.
JxInsta.java
String savedToken = "IGT:2:..."; // previously obtained token
JxInsta client = JxInsta.getInstance(savedToken);
auth
string
required
A valid mobile authentication token previously obtained from a successful login. Must not be null (@NotNull).
Returns — a new JxInsta instance with token set to the supplied value.

Public fields

FieldTypeDescription
usernameStringThe username of the authenticated account. Set only when using the username/password constructor.
passwordStringThe account password. Set only when using the username/password constructor.
tokenStringThe mobile API auth token used for all subsequent requests.

Methods

getProfile(String username)

Fetches a user’s profile by their username. Returns a Profile object that exposes both the raw profile data (inherited from ProfileData) and action methods such as follow, unfollow, and block.
JxInsta.java
JxInsta client = JxInsta.getInstance(token);
Profile profile = client.getProfile("instagram");

System.out.println(profile.name);        // full name
System.out.println(profile.followers);   // follower count
System.out.println(profile.isVerified);  // verification badge
username
string
required
The exact Instagram username of the user whose profile you want to retrieve.
ReturnsProfile ThrowsInstagramException

getFeed()

Returns a FeedPaginator for iterating through the authenticated user’s home feed. The paginator is lazy — it does not make a network request until you call hasNext() and next().
JxInsta.java
FeedPaginator feed = client.getFeed();
while (feed.hasNext()) {
    List<Post> page = feed.next();
    for (Post post : page) {
        System.out.println(post.caption);
    }
}
ReturnsFeedPaginator

getStories()

Fetches the stories tray for the authenticated user. Each element in the returned list is an array of Story objects belonging to a single user’s reel.
JxInsta.java
List<Story[]> storiesTray = client.getStories();
for (Story[] userStories : storiesTray) {
    for (Story story : userStories) {
        System.out.println(story);
    }
}
ReturnsList<Story[]> — a list where each entry holds the stories posted by one account. ThrowsInstagramException

postPicture(InputStream inputStream, String caption, boolean disableLikenComment)

Uploads an image and publishes it as a post on the authenticated account. The image is uploaded first to obtain an upload ID, then configured as a feed post.
JxInsta.java
try (InputStream image = new FileInputStream("photo.jpg")) {
    client.postPicture(image, "Hello from JxInsta!", false);
}
inputStream
InputStream
required
The raw image bytes to upload. Must not be null (@NotNull). The stream is read to completion during the upload step.
caption
string
required
The caption text to attach to the post. Pass an empty string for no caption. Must not be null (@NotNull).
disableLikenComment
boolean
required
When true, disables both the like counter and comments on the published post (comments_disabled=1, like_and_view_counts_disabled=1).
Returnsvoid ThrowsInstagramException (wraps any IOException that occurs during upload as Reasons.IO)

getPost(String url)

Resolves a public Instagram post URL to a Post instance. The method extracts the shortcode from the URL path, converts it to a numeric media ID, and fetches the post detail from the mobile API.
JxInsta.java
Post post = client.getPost("https://www.instagram.com/p/ABC123xyz/");
System.out.println(post.id);        // numeric media ID
System.out.println(post.caption);   // post caption
System.out.println(post.likes);     // like count
url
string
required
The full URL of the Instagram post, e.g. https://www.instagram.com/p/ABC123xyz/. The shortcode is extracted from the /p/<shortcode>/ segment.
ReturnsPost ThrowsInstagramException, IOException

search(String query)

Searches for users matching the supplied query string. Returns up to five results.
JxInsta.java
List<ProfileData> results = client.search("instagram");
for (ProfileData user : results) {
    System.out.println(user.username + " — " + user.followers + " followers");
}
query
string
required
The search term. Must not be null (@NotNull). The API returns at most 5 matching user profiles.
ReturnsList<ProfileData> ThrowsInstagramException

getDirectInbox(int maxThreads, int maxMessages)

Fetches the authenticated user’s direct message inbox. Returns an Inbox object containing all retrieved threads and the usernames of participants.
JxInsta.java
Inbox inbox = client.getDirectInbox(20, 10);
System.out.println("Threads: " + inbox.totalThreads);

for (Thread thread : inbox.threads) {
    System.out.println(thread.recipient + ": " + thread.messages);
}
maxThreads
number
required
The maximum number of conversation threads to return. Maps to the limit query parameter sent to the inbox endpoint.
maxMessages
number
required
The maximum number of messages to load per thread. Maps to the thread_message_limit query parameter.
ReturnsInbox ThrowsInstagramException