List of usage examples for twitter4j TwitterException getMessage
@Override
public String getMessage()
From source file:uk.ac.susx.tag.method51.webapp.handler.TwitterPinAuthHandler.java
License:Apache License
private void pinResponse(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { Params params = new Params(); params.addValidator("response_key", new LongValidator(true)); params.addValidator("id", new SystemStringValidator(true)); params.addValidator("pin", new SystemStringValidator(true)); new DoSomethingAfterValidatingMyParams(params, request, response) { @Override//from ww w . java 2 s . com public void something() throws IOException { long responseKey = Long.parseLong(request.getParameter("response_key")); String pin = request.getParameter("pin"); String name = request.getParameter("id"); if (auths.containsKey(responseKey)) { TwitterPinAuthentication auth = auths.get(responseKey); try { ApiKey apiKey = auth.getAuth(pin); apiKey = new ApiKey(name, apiKey.consumerKey, apiKey.consumerSecret, apiKey.accessToken, apiKey.accessTokenSecret); String id = ApiKeyStore.registerKey(apiKey); LOG.info("key registered : {} {}", id, apiKey); okHereIsYourJson("msg", "Key registered with id " + id + " and name " + name, response); } catch (TwitterException e) { error("Something went wrong with Twitter Pin Auth: " + e.getMessage()); } catch (ApiKeyStoreException e) { error(e.getMessage()); } finally { auths.remove(responseKey); } } else { error("response_key not found, timed out?"); } } }; }
From source file:uk.ac.susx.tag.method51.webapp.handler.TwitterPinAuthHandler.java
License:Apache License
private void getRateLimitInfo(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { final Params params = new Params(); params.addValidator("id", new SystemStringValidator(true)); new DoSomethingAfterValidatingMyParams(params, request, response) { @Override/*from ww w . j av a 2 s. c o m*/ public void something() throws IOException { final String id = request.getParameter("id"); final Twitter twitter = newTwitterInstance(ApiKeyStore.getKey(id)); try { final Map<String, RateLimitStatus> status = twitter.getRateLimitStatus(); okHereIsYourJson(response, entriesToArray(status.entrySet())); } catch (TwitterException e) { LOG.warn("Failed to retrieve rate limit information.", e); error(e.getMessage()); } } }; }
From source file:uk.ac.susx.tag.method51.webapp.handler.TwitterPinAuthHandler.java
License:Apache License
private void getUserInfo(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { final Params params = new Params(); params.addValidator("id", new SystemStringValidator(true)); new DoSomethingAfterValidatingMyParams(params, request, response) { @Override/*from ww w . j av a 2s . c o m*/ public void something() throws IOException { final String id = request.getParameter("id"); final Twitter twitter = newTwitterInstance(ApiKeyStore.getKey(id)); try { final AccountSettings as = twitter.getAccountSettings(); final String userScreenName = twitter.getScreenName(); final long userId = twitter.getId(); final User user = twitter.showUser(userId); okHereIsYourJson(response, "name", user.getName(), "description", user.getDescription(), "created", user.getCreatedAt(), "favourites_count", user.getFavouritesCount(), "followers_count", user.getFollowersCount(), "friends_count", user.getFriendsCount(), "profile_image_url", user.getProfileImageURL(), "screen_name", userScreenName, "user_id", userId, "language", as.getLanguage(), "sleep_time_enabled", as.isSleepTimeEnabled(), "sleep_end_time", as.getSleepEndTime(), "sleep_start_time", as.getSleepStartTime(), "timezone", as.getTimeZone(), "trend_locations", as.getTrendLocations(), "always_use_https", as.isAlwaysUseHttps(), "discoverable_by_email", as.isDiscoverableByEmail(), "geo_enabled", as.isGeoEnabled()); } catch (TwitterException e) { LOG.warn("Failed to retrieve users data.", e); error(e.getMessage()); } } }; }
From source file:uk.co.flax.ukmp.twitter.PartyListHandler.java
License:Apache License
private Set<Long> readPartyIds(Twitter twitter, String screenName, String slug, String party) { Set<Long> ids = new HashSet<>(); try {/*from w ww.j av a 2 s. c o m*/ long cursor = -1; PagableResponseList<User> response = null; do { response = twitter.getUserListMembers(screenName, slug, cursor); for (User user : response) { LOGGER.debug("Read id for user @{}", user.getScreenName()); ids.add(user.getId()); } cursor = response.getNextCursor(); } while (response != null && response.hasNext()); } catch (TwitterException e) { LOGGER.error("Twitter exception updating {} party list : {}", party, e.getMessage()); } return ids; }
From source file:wap.twitter.model.TwitterUtility.java
public List<Tweet> getTweets(String news) { TwitterFactory tf = config();//from w w w. ja v a 2s . co m Twitter twitter = tf.getInstance(); try { List<Tweet> tws = new ArrayList<Tweet>(); int i = 0; Query query = new Query("#" + news); QueryResult result; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { Tweet tw = new Tweet(); if (i == 8) { break; } else { tw.setTitle(news); tw.setUser(tweet.getUser().getScreenName()); tw.setUrl(tweet.getSource()); tw.setImage(tweet.getUser().getProfileImageURL()); tw.setBody(tweet.getText()); tw.setSource(tweet.getSource()); tw.setId(tweet.getId() + ""); i++; } System.out.println("******************* " + tweet.getGeoLocation()); tws.add(tw); } } while ((query = result.nextQuery()) != null); return tws; } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); System.exit(-1); } return null; }
From source file:wap.twitter.model.TwitterUtility.java
private static Integer getTrendLocationId(String locationName) { int idTrendLocation = 0; try {/*ww w. ja v a 2s .c o m*/ ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("yourConsumerKey") .setOAuthConsumerSecret("yourConsumerSecret").setOAuthAccessToken("yourOauthToken") .setOAuthAccessTokenSecret("yourOauthTokenSecret"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); ResponseList<Location> locations; locations = twitter.getAvailableTrends(); for (Location location : locations) { if (location.getName().toLowerCase().equals(locationName.toLowerCase())) { idTrendLocation = location.getWoeid(); break; } } if (idTrendLocation > 0) { return idTrendLocation; } return null; } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get trends: " + te.getMessage()); return null; } }
From source file:wedt.project.MainWindow.java
private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed statusLabel.setText("Trwa wyszukiwanie..."); lockUI();//from w w w. ja va2 s. c o m SwingWorker<List<Status>, Void> worker = new SwingWorker<List<Status>, Void>() { @Override protected List<Status> doInBackground() throws Exception { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("PG0vtiQ73sbKKCfp9JfqyQ") .setOAuthConsumerSecret("ITCkTQiqCh3aVZexXentwnwCJooVpUOcpkIENPKowI") .setOAuthAccessToken("89783194-z0J1KLudg6MFMhhysKmL29zB5wBjxfxWUboAh6lAI") .setOAuthAccessTokenSecret("ytOdt7t8P1OrmAI2ZCRoX30ZC3eLcDSgPY8gOa6FCwQ"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); try { Query query = new Query(searchField.getText()); query.setCount(10); query.setLang("en"); if (checkBoxLatest.isSelected() && checkBoxPopular.isSelected()) query.setResultType(Query.ResultType.mixed); else if (checkBoxLatest.isSelected()) query.setResultType(Query.ResultType.recent); else if (checkBoxPopular.isSelected()) query.setResultType(Query.ResultType.popular); QueryResult result = twitter.search(query); return result.getTweets(); } catch (TwitterException e) { statusLabel.setText("Wyszukiwanie nie powiodlo sie"); e.printStackTrace(); //System.out.println("Failed to search tweets: " + te.getMessage()); JOptionPane.showMessageDialog(null, e.getMessage(), "Blad pobierania wynikow wyszukiwania", JOptionPane.INFORMATION_MESSAGE); } return null; } @Override protected void done() { try { List<Status> tweets = get(); listModel = new DefaultListModel(); tweetsList.setModel(listModel); tweets.stream().forEach((tweet) -> { listModel.addElement(tweet.getText()); }); statusLabel.setText("Gotowe"); } catch (Exception ex) { ex.printStackTrace(); statusLabel.setText("Wyszukiwanie nie powiodlo sie"); } unlockUI(); } }; worker.execute(); }