Coder Social home page Coder Social logo

instagram-java's Introduction

Instagram for Java

Java wrapper for Instagram's API v1

Setup

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.

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, so the required page must also be indicated. The page number is a 0-based index.

  //Endpoint: GET /users/self/feed
  List<Media> user = session.getFeed(1); //first page

Get the most recent media published by a user

Results are paginated, so the required page must also be indicated. The page number is a 0-based index.

  //Endpoint: GET /users/3/media/recent
  int userId = 3;
  int pageNumber = 0; //first page
  List<Media> recentMedia = session.getRecentPublishedMedia(userId, pageNumber);

Search for a user by name

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

Get a user's the followers and follows

Results are paginated, so the required page must also be indicated. The page number is a 0-based index.

  int userId = 3;
  int pageNumber = 0; //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); 

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

instagram-java's People

Contributors

sola92 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.