Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.payammeyer:Instagram-Java:1.3.4'
}
dependencies {
implementation("com.github.payammeyer:Instagram-Java:1.3.4")
}
<dependency>
<groupId>com.github.payammeyer</groupId>
<artifactId>Instagram-Java</artifactId>
<version>1.3.4</version>
</dependency>
libraryDependencies += "com.github.payammeyer" % "Instagram-Java" % "1.3.4"
:dependencies [[com.github.payammeyer/Instagram-Java "1.3.4"]]
Java wrapper for Instagram's API v1
<dependency>
<groupId>com.github.sola92</groupId>
<artifactId>instagram-java</artifactId>
<version>1.3.9</version>
</dependency>
Firstly, build the authorization URL
InstagramAuthentication auth = new InstagramAuthentication();
String authUrl = auth.setRedirectUri("your_redirect_url")
.setClientSecret("your_app_secrect")
.setClientId("your_client_id")
.setScope("comments+likes")
.getAuthorizationUri();
After the user has authorized the app, get the access token by passing the code given in the callback URL.
AccessToken token = auth.build("code");
Create the session using the access token and you're all set
InstagramSession session = new InstagramSession(token);
User rihanna = session.searchUsersByName("badgalriri").get(0);
Here are some common endpoint calls. Please refer to the javadoc at /doc/com/sola/instagram/InstgramSession.html
for the full documentation of the endpoints.
//Endpoint: GET /users/3
User user = session.getUserById(3);
//Endpoint: GET /users/self/feed
PaginatedCollection<Media> feed = session.getFeed();
for(Media media: feed) {
//do stuff
}
//Endpoint: GET /users/3/media/recent
int userId = 3;
PaginatedCollection<Media> recentMedia = session.getRecentPublishedMedia(userId);
for(Media media: recentMedia) {
//do stuff
}
//Endpoint: GET /media/5233810105500317233
Media media = session.getMedia("523381010550031723");
//check for video
if (media instanceof VideoMedia) {
VideoMedia video = (VideoMedia)media;
}
//Endpoint: GET /users/search?q=jack
List<User> searchResults = session.searchUsersByName("jack");
int userId = 3;
// GET /users/3/follows
PaginatedCollection<User> follows = session.getFollows(userId);
// GET /users/3/followed-by
PaginatedCollection<User> followers = session.getFollowers(userId);
int targetUserId = 3;
// POST /users/3/relationship
session.modifyRelationship(targetUserId, Relationship.Action.FOLLOW)
int targetUserId = 3;
// POST /users/3/relationship
session.modifyRelationship(targetUserId, Relationship.Action.UNFOLLOW)
//routes api requests through a proxy
session.setHttpProxy("180.180.121.156", 8080);
//remove the proxy
session.removeHttpProxy();
Copyright (c) 2013 Sola Ogunsakin Licensed under the MIT license.