Java wrapper for Instagram's API v1
Include the /bin/java-instagram.jar
file in your project.
This library has a dependence on Apache HttpClient 4.2.1. It can be downloaded here.
Firstly, build the authorization URL
InstagramAuthentication auth = new InstagramAuthentication();
String authUrl = auth.setRedirectUri("your_redirect_url")
.setClientSecret("your_app_secrect")
.setClientId("your_client_id")
.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);
Results are paginated, so the required page must also be indicated. The page number is a 1-based index.
//Endpoint: GET /users/self/feed
List<Media> user = session.getFeed(1); //first page
Results are paginated, so the required page must also be indicated. The page number is a 1-based index.
//Endpoint: GET /users/3/media/recent
int userId = 3;
int pageNumber = 1; //first page
List<Media> recentMedia = session.getRecentPublishedMedia(userId, pageNumber);
//Endpoint: GET /users/search?q=jack
List<User> searchResults = session.searchUsersByName("jack");
Results are paginated, so the required page must also be indicated. The page number is a 1-based index.
int userId = 3;
int pageNumber = 1; //first page
// GET /users/3/follows
List<User> follows = session.getFollows(userId, pageNumber);
// GET /users/3/followed-by
List<User> followers = session.getFollowers(userId, pageNumber);
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)
Copyright (c) 2013 Sola Ogunsakin Licensed under the MIT license.
- Email : [email protected]
- LinkedIn : http://ca.linkedin.com/pub/sola-ogunsakin/45/a5/5a0/
- Twitter : @SolaOgunsakin