private void grabTrending() { try { if (VERBOSE) { DAO.log("Kaizen is going to get trending topics ..."); } for (Location location : twitter.trends().getAvailableTrends()) { for (Trend trend : twitter.trends().getPlaceTrends(location.getWoeid()).getTrends()) { this.queries.addQuery(trend.getQuery()); } } } catch (TwitterException e) { if (e.getErrorCode() != 88) { DAO.severe(e); } } }
@Override public ImportResult importItem( UUID jobId, TokenSecretAuthData authData, PhotosContainerResource data) { Twitter twitterApi = TwitterApiWrapper.getInstance(appCredentials, authData); // Twitter doesn't support an 'Albums' concept, so that information is just lost. for (PhotoModel image : data.getPhotos()) { try { StatusUpdate update = new StatusUpdate(image.getDescription()); InputStreamContent content = new InputStreamContent(null, getImageAsStream(image.getFetchableUrl())); update.media(image.getTitle(), content.getInputStream()); twitterApi.tweets().updateStatus(update); } catch (IOException | TwitterException e) { monitor.severe(() -> "Error importing twitter photo", e); return new ImportResult(e); } } return new ImportResult(ResultType.OK); }
@Override public User getUser(final Principal principal, final Long id) throws WTFDYUMException { User result = null; try { final twitter4j.User user = twitter(principal).users().showUser(id); result = mapper.map(user, User.class); } catch (final TwitterException e) { log.debug("Error while getUser", e); throw new WTFDYUMException(e, WTFDYUMExceptionType.TWITTER_ERROR); } return result; }
@Override public List<User> getUsers(final Principal principal, final long... ids) throws WTFDYUMException { final List<User> result = new ArrayList<>(); if (ids.length == 0) { return result; } try { final List<twitter4j.User> users = new ArrayList<>(); for (int i = 0; i <= (ids.length - 1) / 100; i++) { final ResponseList<twitter4j.User> lookupUsers = twitter(principal).users() .lookupUsers(Arrays.copyOfRange(ids, i * 100, Math.min((i + 1) * 100, ids.length))); users.addAll(lookupUsers); } for (final twitter4j.User u : users) { result.add(mapper.map(u, User.class)); } } catch (final TwitterException e) { if (e.getErrorCode() == 17) { log.debug("Error while getUsers for ids: " + Arrays.toString(ids) + ". Seems like those users are not on twitter anymore."); } else { log.debug("Error while getUsers for ids: " + Arrays.toString(ids), e); throw new WTFDYUMException(e, WTFDYUMExceptionType.TWITTER_ERROR); } } return result; }