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
The Instagram account username.
The account password. The library encrypts it before transmission using the
#PWD_INSTAGRAM_BROWSER:0:<timestamp>:<password> scheme.| Exception | Reason |
|---|---|
IOException | A network or I/O error occurred before receiving a response. |
InstagramException | Authentication 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
A valid mobile authentication token previously obtained from a successful login. Must not be null (
@NotNull).JxInsta instance with token set to the supplied value.
Public fields
| Field | Type | Description |
|---|---|---|
username | String | The username of the authenticated account. Set only when using the username/password constructor. |
password | String | The account password. Set only when using the username/password constructor. |
token | String | The 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
The exact Instagram username of the user whose profile you want to retrieve.
Profile
Throws — InstagramException
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
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[]> — a list where each entry holds the stories posted by one account.
Throws — InstagramException
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
The raw image bytes to upload. Must not be null (
@NotNull). The stream is read to completion during the upload step.The caption text to attach to the post. Pass an empty string for no caption. Must not be null (
@NotNull).When
true, disables both the like counter and comments on the published post (comments_disabled=1, like_and_view_counts_disabled=1).void
Throws — InstagramException (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
The full URL of the Instagram post, e.g.
https://www.instagram.com/p/ABC123xyz/. The shortcode is extracted from the /p/<shortcode>/ segment.Post
Throws — InstagramException, IOException
search(String query)
Searches for users matching the supplied query string. Returns up to five results.
JxInsta.java
The search term. Must not be null (
@NotNull). The API returns at most 5 matching user profiles.List<ProfileData>
Throws — InstagramException
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
The maximum number of conversation threads to return. Maps to the
limit query parameter sent to the inbox endpoint.The maximum number of messages to load per thread. Maps to the
thread_message_limit query parameter.Inbox
Throws — InstagramException