/instagram4j

:camera: Java port to Instagram's private API

Primary LanguageJavaApache License 2.0Apache-2.0

instagram4j

Apache License Build Status Maven Central PRs Welcome

📷 Java client to Instagram's private API. Allows access to all the features that 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.0</version>
</dependency>

or Gradle:

compile 'org.brunocvcunha.instagram4j:instagram4j:1.0'

Supported Operations & Examples

Login

// Login to instagram
Instagram4j instagram = Instagram4j.builder().username("username").password("password").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 your feed

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

Upload a video 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

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

Perform a like operation for a media

instagram.sendRequest(new InstagramLikeRequest(feedResult.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.