コード例 #1
0
 @NonNull
 public static User showUserAlternative(
     final Twitter twitter, final long id, final String screenName) throws TwitterException {
   final String searchScreenName;
   if (screenName != null) {
     searchScreenName = screenName;
   } else if (id != -1) {
     searchScreenName = twitter.showFriendship(id).getTargetUserScreenName();
   } else throw new IllegalArgumentException();
   final Paging paging = new Paging();
   paging.count(1);
   for (final User user : twitter.searchUsers(searchScreenName, paging)) {
     if (user.getId() == id || searchScreenName.equalsIgnoreCase(user.getScreenName()))
       return user;
   }
   if (id != -1) {
     final ResponseList<Status> timeline = twitter.getUserTimeline(id, paging);
     for (final Status status : timeline) {
       final User user = status.getUser();
       if (user.getId() == id) return user;
     }
   } else {
     final ResponseList<Status> timeline = twitter.getUserTimeline(screenName, paging);
     for (final Status status : timeline) {
       final User user = status.getUser();
       if (searchScreenName.equalsIgnoreCase(user.getScreenName())) return user;
     }
   }
   throw new TwitterException("can't find user");
 }
コード例 #2
0
 @Override
 protected final List<User> getUsers(final Twitter twitter) throws TwitterException {
   if (twitter == null) return null;
   final Paging paging = new Paging();
   paging.count(getCount());
   if (getCursor() > 0) {
     paging.setCursor(getCursor());
   }
   final PageableResponseList<User> users = getCursoredUsers(twitter, paging);
   if (users == null) return null;
   setCursorIds(users);
   return users;
 }