Skip to content

Quick Start

Rahil edited this page Apr 14, 2026 · 3 revisions

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.

πŸš€ Getting Started

Login with username/password

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

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

Reuse an existing auth token

JxInsta insta = JxInsta.getInstance(AUTH_TOKEN);

πŸ’‘ Tip: Save your AUTH_TOKEN and reuse it to avoid logging in every time.

πŸ‘€ Profiles

Fetch and follow someone:

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

Search users:

var results = insta.search("query");
results.forEach(pd -> System.out.println(pd.username + " β€” " + pd.fullName));

πŸ“° Feed

Scroll through your feed:

var feed = insta.getFeed(); // FeedPaginator
while (feed.hasNext()) {
    var page = feed.next();
    page.items.forEach(item -> System.out.println(item.id));
}

πŸ“– Stories

Get stories:

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

πŸ“Έ Posting

Upload a picture:

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

πŸ”— Posts

Fetch a post by URL:

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

πŸ’¬ Direct Messages

Check your inbox:

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);
}

πŸ“ Quick Tips

  • Save your AUTH_TOKEN for faster reuse.
  • postPicture needs a valid InputStream (correct format & size).
  • Explore classes like FeedPaginator, Profile, Post, and Inbox for more features.

For brief understanding of each Instagram endpoint, you can view the docs for respective class.

Clone this wiki locally