Skip to content

AaronCLH/Instagram-Java

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Instagram for Java

Java wrapper for Instagram's API v1

Maven Setup

<dependency>
    <groupId>com.github.sola92</groupId>
    <artifactId>instagram-java</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

Authentication

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);

Endpoint Examples

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.

Get basic information about a user

  //Endpoint: GET /users/3
  User user = session.getUserById(3);

See the authenticated user's feed, results are paginated

  //Endpoint: GET /users/self/feed
  PaginatedCollection<Media> feed = session.getFeed(); 
  for(Media media: feed) {
    //do stuff
  }

Get a list of the most recent media published by a user

  //Endpoint: GET /users/3/media/recent
  int userId = 3;
  PaginatedCollection<Media> recentMedia = session.getRecentPublishedMedia(userId);
  for(Media media: recentMedia) {
    //do stuff
  }  

Get a media object

  //Endpoint: GET /media/5233810105500317233
  Media media = session.getMedia("523381010550031723");
  //check for video
  if (media instanceof VideoMedia) { 
    VideoMedia video = (VideoMedia)media;
  }  

Search for a user by name

  //Endpoint: GET /users/search?q=jack
  List<User> searchResults = session.searchUsersByName("jack");

Get a list of the user's followers and follows

  int userId = 3;
  // GET /users/3/follows
  PaginatedCollection<User> follows = session.getFollows(userId); 
  // GET /users/3/followed-by
  PaginatedCollection<User> followers = session.getFollowers(userId); 

Follow a user

  int targetUserId = 3;
  // POST /users/3/relationship
  session.modifyRelationship(targetUserId, Relationship.Action.FOLLOW)

Unfollow a user

  int targetUserId = 3;
  // POST /users/3/relationship
  session.modifyRelationship(targetUserId, Relationship.Action.UNFOLLOW)

License

Copyright (c) 2013 Sola Ogunsakin Licensed under the MIT license.

About me

About

Java wrapper for Instagram's API v1

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published