instagram4j

:camera: Java port to Instagram's private API

Github星跟踪图

instagram4j

Apache License
Build Status
Maven Central PRs Welcome
Code Climate

:camera: 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.

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.

主要指标

概览
名称与所有者instagram4j/instagram4j
主编程语言Java
编程语言Java (语言数: 1)
平台
许可证Apache License 2.0
所有者活动
创建于2017-02-04 03:12:35
推送于2023-08-20 02:37:33
最后一次提交2022-01-23 17:25:47
发布数23
最新版本名称2.0.7 (发布于 )
第一版名称instagram4j-1.0 (发布于 2017-02-08 20:31:36)
用户参与
星数0.9k
关注者数68
派生数270
提交数612
已启用问题?
问题数592
打开的问题数101
拉请求数77
打开的拉请求数11
关闭的拉请求数36
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?