Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

jInstagram Usage

Sachin Handiekar edited this page Jul 27, 2011 · 38 revisions

Using jInstagram

Creating the Instagram Object

Instagram instagram = new Instagram(accessToken);

##Instagram API Endpoints

###Users

  • Get basic information about a user.

      long userId = 3;
      UserInfo userInfo = instagram.getUserInfo(userId);
    
      UserInfoData userData = userInfo.getData();
      System.out.println("id : " + userData.getId());
      System.out.println("first_name : " + userData.getFirst_name());
      System.out.println("last_name : " + userData.getLast_name());
      System.out.println("profile_picture : " + userData.getProfile_picture());
      System.out.println("website : " + userData.getWebsite());
    
  • See the authenticated user's feed.

      MediaFeed mediaFeed = instagram.getUserFeeds();
      List<MediaFeedData> mediaFeeds = mediaFeed.getData();
    
      for (MediaFeedData mediaData : mediaFeeds) {
      	System.out.println("id : " + mediaData.getId());
      	System.out.println("created time : " + mediaData.getCreatedTime());
      	System.out.println("link : " + mediaData.getLink());
      	System.out.println("tags : " + mediaData.getTags().toString());
      	System.out.println("filter : " + mediaData.getImageFilter());
      	System.out.println("type : " + mediaData.getType());
    
      	System.out.println("-- Comments --");
      	Comments comments = mediaData.getComments();
    
      	System.out.println("-- Caption --");
      	Caption caption = mediaData.getCaption();
    
      	System.out.println("-- Likes --");
      	Likes likes = mediaData.getLikes();
    
      	System.out.println("-- Images --");
      	Images images = mediaData.getImages();
    
      	ImageData lowResolutionImg = images.getLowResolution();
      	ImageData highResolutionImg = images.getHighResolution();
      	ImageData thumbnailImg = images.getThumbnail();
    
      	Location location = mediaData.getLocation();
      	System.out.println();
      }
    
  • Get the most recent media published by a user.

      long userId = 3;
      MediaFeed mediaFeed = instagram.getRecentMediaFeed(userId);
    
  • See the authenticated user's list of media they've liked.

  • Search for a user by name.

       String query = "jack";
       UserFeed userFeed = instagram.searchUser(query);
      
       List<UserFeedData> userList = userFeed.getUserList();
       
      //Please see the UserFeedData element for more usage. 
    

###Relationship

  • Get the list of users this user follows.

      long userId = 3;
      UserFeed feed = instagram.getUserFollowList(userId);
      List<UserFeedData> users = feed.getUserList();
    
      //Please see the UserFeedData element for more usage. 
    
  • Get the list of users this user is followed by.

      long userId = 3;
      UserFeed feed = instagram.getUserFollowedByList(userId);
      List<UserFeedData> users = feed.getUserList();
      
      //Please see the UserFeedData element for more usage. 
    
  • List the users who have requested this user's permission to follow

      UserFeed feed = instagram.getUserRequestedBy();		 
      List<UserFeedData> users = feed.getUserList();
    
  • Get information about the current user's relationship (follow/following/etc) to another user.

      long userId = 3;
      RelationshipFeed feed = instagram.getUserRelationship(userId);
       
      System.out.println("incoming_status : " + feed.getData().getIncomingStatus());
      System.out.println("outgoing_status : " + feed.getData().getOutgoingStatus());
    
  • Modify the relationship between the current user and the target user

      long userId = 3;
      RelationshipFeed feed = instagram.setUserRelationship(userId, Relationship.FOLLOW);
       
      System.out.println("Meta Code : "       + feed.getMeta().getCode());		
      System.out.println("Incoming_Status : " + feed.getData().getIncomingStatus());
    

###Media

  • Get information about a media object.

      long mediaId = 3;		
      MediaInfoFeed mediaInfoFeed = instagram.getMediaInfo(mediaId); 		 
      System.out.println("id : "           + mediaInfoFeed.getData().getId());
      System.out.println("created_time : " + mediaInfoFeed.getData().getCreatedTime());
      
      //Please see the MediaInfoFeed element for more usage.
    
  • Search for media in a given area.

      double latitude = 48.858844;
      double longitude = 2.294351;
      
      MediaFeed feed = instagram.searchMedia(latitude, longitude);		 
      List<MediaFeedData> feeds = feed.getData();
      
      // Please see the MediaFeedData element for more usage.
    
  • Get a list of what media is most popular at the moment.

      MediaFeed feed = instagram.getPopularMedia();
    

###Comments

  • Get a full list of comments on a media.

      long mediaId = 555;
    
      MediaCommentsFeed feed = instagram.getMediaComments(mediaId);
      List<CommentData> comments = feed.getCommentDataList();
    
      for (CommentData comment : comments) {
      	System.out.println("id : " + comment.getId());
      	System.out.println("created_time : " + comment.getCreatedTime());
      	System.out.println("text : " + comment.getText());
    
      }
    
  • Create a comment on a media.

      long mediaId = 142856861;
    
      MediaCommentResponse response = instagram.setMediaComments(mediaId, "Sample Comment");
      CommentData commentData = response.getCommentData();
    
  • Remove a comment either on the authenticated user's media or authored by the authenticated user.

      long mediaId = 12345;
      long commentId = 123456;
      MediaCommentResponse response = instagram.deleteMediaCommentById(mediaId, commentId);
      
      Meta meta = response.getMeta();
      System.out.println("Code : " + meta.getCode());
    

###Likes

  • Get a list of users who have liked this media.

      long mediaId = 555;
      LikesFeed feed = instagram.getUserLikes(mediaId);
    
      List<User> users = feed.getUserList();
    
      for (User user : users) {
      	System.out.println("id : " + user.getId());
      	System.out.println("full_name : " + user.getFullName());
      	System.out.println("user_name : " + user.getUserName());
      	System.out.println("profile_picture : " + user.getProfilePictureUrl());
      	System.out.println("website : " + user.getWebsiteUrl());
      	System.out.println();
    
      }
    
  • Set a like on this media by the currently authenticated user.

  • Remove a like on this media by the currently authenticated user.

###Tag

  • Get information about a tag object.

      String tagName = "nofilter";
      TagInfoFeed feed = instagram.getTagInfo(tagName);
    
      TagInfoData tagData = feed.getTagInfo();
      System.out.println("name : " + tagData.getTagName());
      System.out.println("media_count : " + tagData.getMediaCount());
    
  • Get a list of recently tagged media.

      String tagName = "snow";
      TagMediaFeed mediaFeed = instagram.getRecentMediaTags(tagName);
      
      List<MediaFeedData> mediaFeeds = mediaFeed.getData();
    
  • Search for tags by name - results are ordered first as an exact match, then by popularity.

      String query = "snow";
      TagSearchFeed searchFeed = instagram.searchTags(query);
    
      List<TagInfoData> tags = searchFeed.getTagList();
    
      for (TagInfoData tagData : tags) {
      	System.out.println("name : " + tagData.getTagName());
      	System.out.println("media_count : " + tagData.getMediaCount());
      	System.out.println();
      }
    

###Location

  • Get information about a location.

      long locationId = 1;
      LocationInfo locationInfo = instagram.getLocationInfo(locationId);		
      
      Location location = locationInfo.getLocationData();
       
      System.out.println("id : " + location.getId());
      System.out.println("name : " + location.getName());
      System.out.println("latitude : " + location.getLatitude());
      System.out.println("longitude : " + location.getLongitude());
    

    }

  • Get a list of recent media objects from a given location.

      long locationId=514276;
      MediaFeed mediaFeed = instagram.getRecentMediaByLocation(locationId);		
      
      List<MediaFeedData> mediaFeeds = mediaFeed.getData();
    
      //Please see the MediaFeed Element for more details....
    
  • Search for a location by geographic coordinate.

      double latitude = 48.858844;
      double longitude = 2.29435;
      LocationSearchFeed searchFeed = instagram.searchLocation(latitude, longitude);
    
      for (Location location : searchFeed.getLocationList()) {
      	System.out.println("id : " + location.getId());
      	System.out.println("name : " + location.getName());
      	System.out.println("latitude : " + location.getLatitude());
      	System.out.println("longitude : " + location.getLongitude());
      	System.out.println();
      }
    

##Common Data Elements

  • Meta

      Meta meta = mediaFeed.getMeta();
      
      System.out.println("code : " + meta.getCode());
      System.out.println("error message : " + meta.getErrorMessage());
      System.out.println("error type : " + meta.getErrorType());
    
  • UserFeedData

      List<UserFeedData> users = feed.getUserList();
    
      for (UserFeedData user : users) {
          System.out.println("id : "              + user.getId());
      	System.out.println("username : " + user.getUserName());
      	System.out.println("first_name : " + user.getFirstName());
      	System.out.println("last_name : "       + user.getLastName());
      	System.out.println("profile_picture : " + user.getProfilePictureUrl());	
      }
    
  • Caption

      Caption caption = mediaData.getCaption();
      System.out.println("id : "              + caption.getId());
      System.out.println("created time : "    + caption.getCreatedTime());
      System.out.println("text : "            + caption.getText());
      
      System.out.println("** From **");
      System.out.println("id : "              + caption.getFrom().getId());
      System.out.println("full name : "       + caption.getFrom().getFullName());
      System.out.println("user name : "       + caption.getFrom().getUsername());
      System.out.println("profile picture : " + caption.getFrom().getProfilePicture());
    
  • Comments

      Comments comments = mediaData.getComments();
      List<CommentData> commentList = comments.getComments();
    
      for (CommentData comment : commentList) {
      	System.out.println("commentId : "    + comment.getId());
      	System.out.println("created Time : " + comment.getCreatedTime());
      	System.out.println("text : "         + comment.getText());
      	
      	System.out.println("** From **");
      	System.out.println("id : "        + comment.getCommentFrom().getId());
      	System.out.println("full name : " + comment.getCommentFrom().getFullName());
      	System.out.println("user name : " + comment.getCommentFrom().getUsername());
      	System.out.println("profile picture : " + comment.getCommentFrom().getProfilePicture());
    
  • Location

Location location = mediaData.getLocation();
System.out.println("id : "        + location.getId());
System.out.println("name : "      + location.getName());
System.out.println("latitude : "  + location.getLatitude());
System.out.println("longitude : " + location.getLongitude());
  • ImageData

      ImageData lowResolutionImg = images.getLowResolution();
    
      System.out.println("url : "    + lowResolutionImg.getImageUrl());
      System.out.println("width : "  + lowResolutionImg.getImageWidth());
      System.out.println("height : " + lowResolutionImg.getImageHeight());     
    
  • Likes

  • Pagination

  • User

  • Comment

Clone this wiki locally