Skip to content
📷 Java port to Instagram's private API
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.mvn/wrapper Add mvn wrapper Aug 8, 2018
src/main/java/org/brunocvcunha/instagram4j Merge pull request #358 from evosystem-jp/master Nov 6, 2019
.gitignore Add mvn wrapper Aug 8, 2018
.travis.yml Use openjdk8 Jul 23, 2019
LICENSE initial commit Feb 4, 2017
README.md Update README.md Nov 6, 2019
mvnw Add mvn wrapper Aug 8, 2018
mvnw.cmd Add mvn wrapper Aug 8, 2018
pom.xml dependency: use fixed version for Jackson Nov 6, 2019

README.md

instagram4j

Apache License Build Status Maven Central PRs Welcome Code Climate

📷 Java client to Instagram's private API. Allows access to all features that the Instagram app provides.

Based on the Instagram PHP Api and Instagram Python Api.

Usage

Download the latest release JAR or grab via Maven:

<dependency>
  <groupId>org.brunocvcunha.instagram4j</groupId>
  <artifactId>instagram4j</artifactId>
  <version>1.13</version>
</dependency>

or Gradle:

compile 'org.brunocvcunha.instagram4j:instagram4j:1.13'

Supported Operations & Examples

Login

// Login to instagram
Instagram4j instagram = Instagram4j.builder().username("username").password("password").build();
instagram.setup();
instagram.login();

Login with proxy without authentication

// Login to instagram

HttpHost proxy = new HttpHost("host", "port", "http");
Instagram4j instagram = Instagram4j.builder().username("username").password("password").proxy(proxy).build();
instagram.setup();
instagram.login();

Login with proxy with authentication

// Login to instagram

HttpHost proxy = new HttpHost("host", "port", "http");
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY),
                new UsernamePasswordCredentials("login", "password"));
        
        
Instagram4j instagram = Instagram4j.builder().username("username").password("password").proxy(proxy).credentialsProvider(credentialsProvider).build();
instagram.setup();
instagram.login();

Search user by handle

InstagramSearchUsernameResult userResult = instagram.sendRequest(new InstagramSearchUsernameRequest("github"));
System.out.println("ID for @github is " + userResult.getUser().getPk());
System.out.println("Number of followers: " + userResult.getUser().getFollower_count());

Follow user

instagram.sendRequest(new InstagramFollowRequest(userResult.getUser().getPk()));

Unfollow user

instagram.sendRequest(new InstagramUnfollowRequest(userResult.getUser().getPk()));

Get user followers

InstagramGetUserFollowersResult githubFollowers = instagram.sendRequest(new InstagramGetUserFollowersRequest(userResult.getUser().getPk()));
List<InstagramUserSummary> users = githubFollowers.getUsers();
for (InstagramUserSummary user : users) {
    System.out.println("User " + user.getUsername() + " follows Github!");
}

Search user by handle

InstagramSearchUsernameResult userResult = instagram.sendRequest(new InstagramSearchUsernameRequest("github"));
System.out.println("ID for @github is " + userResult.getUser().getPk());
System.out.println("Number of followers: " + userResult.getUser().follower_count);

Upload a photo to your feed

instagram.sendRequest(new InstagramUploadPhotoRequest(
        new File("/tmp/file-to-upload.jpg"),
        "Posted with Instagram4j, how cool is that?"));

Upload a video to your feed

instagram.sendRequest(new InstagramUploadVideoRequest(
        new File("/tmp/file-to-upload.mp4"),
        "Video posted with Instagram4j, how cool is that?"));

Get feed for a hashtag

InstagramFeedResult tagFeed = instagram.sendRequest(new InstagramTagFeedRequest("github"));
for (InstagramFeedItem feedResult : tagFeed.getItems()) {
    System.out.println("Post ID: " + feedResult.getPk());
}

Perform a like operation for a media

instagram.sendRequest(new InstagramLikeRequest(feedResult.getPk()));

Add a comment for a media

instagram.sendRequest(new iInstagramPostCommentRequest(feedResult.getPk(), "Hello! How are you?"));

Get comments from media

InstagramGetMediaCommentsResult commentsResult = instagram.sendRequest(new InstagramGetMediaCommentsRequest(mediaId, maxCommentId));

Share message

recipients - List of recipients IDs (i.e. "1234567890")
instagram.sendRequest(InstagramDirectShareRequest.builder(ShareType.MESSAGE, recipients).message(message).build());

Share media

recipients - List of recipients IDs (i.e. "1234567890")
instagram.sendRequest(InstagramDirectShareRequest.builder(ShareType.MEDIA, recipients).mediaId(mid).message(message).build());

Edit media

InstagramEditMediaRequest r = new InstagramEditMediaRequest(mediaId, caption);
UserTags tags = r.new UserTags();
tags.getTagsToAdd().add(r.new UserTag(userId, posX, posY));
tags.getTagsToAdd().add(r.new UserTag(userId2, posX2, posY2));
tags.getUserIdsToRemoveTag().add("1231231231");
tags.getUserIdsToRemoveTag().add("3213213213");
r.setUserTags(tags);
instagram.sendRequest(r);

Mute Post and Story

instagram.sendRequest(new InstagramMuteStoryAnPostRequest(userResult.getUser().getPk()));

Mute Post

instagram.sendRequest(new InstagramMutePostRequest(userResult.getUser().getPk()));

Mute Story

instagram.sendRequest(new InstagramMuteStoryRequest(userResult.getUser().getPk()));

(More operations to be added)

Building from the source

git clone https://github.com/brunocvcunha/instagram4j
cd instagram4j
mvn clean install

Snapshots of the development version are available in Sonatype's snapshots repository.

instagram4j requires at minimum Java 8.

Terms and conditions

  • You will NOT use this API for marketing purposes (spam, botting, harassment, massive bulk messaging...).
  • We do NOT give support to anyone who wants to use this API to send spam or commit other crimes.
  • We reserve the right to block any user of this repository that does not meet these conditions.

Legal

This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by Instagram or any of its affiliates or subsidiaries. This is an independent and unofficial API. Use at your own risk.

You can’t perform that action at this time.