Skip to content
Rahil edited this page Apr 13, 2026 · 2 revisions

JxInsta — Quick start

This documentation focuses on the mobile module (com.jxinsta.mobile). The web module shares ~99% of the design and the same examples below can be used as a guide for the web variant (package com.jxinsta.web) with minor API differences (session/csrf vs auth token).

Only concise, runnable-style examples for the mobile module are shown. Handle IOException and InstagramException where noted.

Quick notes

  • Mobile class: com.jxinsta.mobile.JxInsta
  • Many methods throw InstagramException (and some IOExceptions) — catch or propagate as needed.
  • You can create an instance either by logging in (username/password) or by reusing an existing auth token.

Examples

Login (username/password)

import com.jxinsta.mobile.JxInsta;
import com.jxinsta.mobile.InstagramException;

try {
    JxInsta insta = new JxInsta("USERNAME", "PASSWORD");
    // use insta...
} catch (IOException | InstagramException e) {
    e.printStackTrace();
}

Reuse existing auth token

JxInsta insta = JxInsta.getInstance(AUTH_TOKEN);

Fetch profile and follow

var profile = insta.getProfile("target_username"); // returns Profile
profile.follow();
System.out.println("bio: " + profile.bio);

Feed paginator (mobile)

var feed = insta.getFeed(); // returns mobile FeedPaginator
// iterate using FeedPaginator API (see FeedPaginator class for methods)
while (feed.hasNext()) {
    var page = feed.next();
    page.items.forEach(item -> System.out.println(item.id));
}

Stories (mobile)

List<Story[]> stories = insta.getStories();
for (var userStories : stories) {
    for (var s : userStories) {
        System.out.println(s.username + " -> " + s.url);
    }
}

Post a picture (mobile)

try (InputStream in = new FileInputStream("photo.jpg")) {
    insta.postPicture(in, "Caption text", false); // false => likes/comments enabled
}

Fetch a post by URL

var post = insta.getPost("https://www.instagram.com/p/SHORTCODE/");
System.out.println(post.caption);

Search users (mobile)

List<com.jxinsta.mobile.endpoints.profile.ProfileData> results = insta.search("query");
results.forEach(pd -> System.out.println(pd.username + " — " + pd.fullName));

Direct inbox (mobile)

var inbox = insta.getDirectInbox(10, 5); // maxThreads, maxMessages
System.out.println("total threads: " + inbox.totalThreads);
if (!inbox.threads.isEmpty()) {
    System.out.println("first thread recipient: " + inbox.threads.getFirst().recipient);
}

Minimal tips

  • Preserve AUTH_TOKEN between runs to avoid re-login; use JxInsta.getInstance(AUTH_TOKEN).
  • postPicture requires a valid InputStream; ensure image format and size are acceptable.
  • See FeedPaginator, Profile, Post, and Inbox classes for more detailed usage patterns.

Clone this wiki locally