List of usage examples for twitter4j TwitterException getMessage
@Override
public String getMessage()
From source file:ehealth.external.twitter.UpdateStatus.java
License:Apache License
private void loginTwitter() { File file = new File("twitter4j.properties"); Properties prop = new Properties(); InputStream is = null;/* w ww .ja v a 2 s . co m*/ OutputStream os = null; try { if (file.exists()) { is = new FileInputStream(file); prop.load(is); } prop.setProperty("oauth.consumerKey", "2JaAM5RaAv56zT3HxI6fpp6Nq"); prop.setProperty("oauth.consumerSecret", "SRzpW5f4vk4QYeFPtJR7whQvjmM75D1JuBHTP4blTPCWu77Acl"); os = new FileOutputStream("twitter4j.properties"); prop.store(os, "twitter4j.properties"); } catch (IOException ioe) { ioe.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException ignore) { } } if (os != null) { try { os.close(); } catch (IOException ignore) { } } } try { try { // get request token. // this will throw IllegalStateException if access token is // already available RequestToken requestToken = twitter.getOAuthRequestToken(); System.out.println("Got request token."); System.out.println("Request token: " + requestToken.getToken()); System.out.println("Request token secret: " + requestToken.getTokenSecret()); AccessToken accessToken = null; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (null == accessToken) { System.out.println("Open the following URL and grant access to your account:"); System.out.println(requestToken.getAuthorizationURL()); try { Desktop.getDesktop().browse(new URI(requestToken.getAuthorizationURL())); } catch (UnsupportedOperationException ignore) { } catch (IOException ignore) { } catch (URISyntaxException e) { throw new AssertionError(e); } System.out.print("Enter the PIN(if available) and hit enter after you granted access.[PIN]:"); String pin = br.readLine(); try { if (pin.length() > 0) { accessToken = twitter.getOAuthAccessToken(requestToken, pin); } else { accessToken = twitter.getOAuthAccessToken(requestToken); } } catch (TwitterException te) { if (401 == te.getStatusCode()) { System.out.println("Unable to get the access token."); } else { te.printStackTrace(); } } } System.out.println("Got access token."); System.out.println("Access token: " + accessToken.getToken()); System.out.println("Access token secret: " + accessToken.getTokenSecret()); try { prop.setProperty("oauth.accessToken", accessToken.getToken()); prop.setProperty("oauth.accessTokenSecret", accessToken.getTokenSecret()); os = new FileOutputStream(file); prop.store(os, "twitter4j.properties"); os.close(); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(-1); } finally { if (os != null) { try { os.close(); } catch (IOException ignore) { } } } } catch (IllegalStateException ie) { // access token is already available, or consumer key/secret is // not set. if (!twitter.getAuthorization().isEnabled()) { System.out.println("OAuth consumer key/secret is not set."); } } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); } catch (IOException ioe) { ioe.printStackTrace(); System.out.println("Failed to read the system input."); } catch (Exception e) { } }
From source file:ehealth.external.twitter.UpdateStatus.java
License:Apache License
/** * Post tweets on Twitter// w w w .j av a2 s .c o m * * @param tweet * */ public int postTwitterStatus(String tweet) { try { loginTwitter(); Status status = twitter.updateStatus(tweet); System.out.println("Successfully updated the status to [" + status.getText() + "]."); return 1; } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); } catch (Exception e) { } return 0; }
From source file:es.upm.oeg.entity.extractor.extractor.gate.TwitterCorpus.java
public void createCorpus() { repository = new FarolasRepo(); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();//from www . j a v a2 s . c om try { corpus = Factory.newCorpus("tweetcorpus"); Query query = new Query(queryString); //"oddfarolas" QueryResult result; result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { Document doc = Factory.newDocument(tweet.getText()); doc.setName(String.valueOf(tweet.getId())); corpus.add(doc); logger.info(tweet.getId() + " @" + tweet.getUser().getScreenName() + " - " + tweet.getText() + " -" + tweet.getGeoLocation()); repository.instanciateNew(String.valueOf(tweet.getId()), tweet.getUser().getScreenName(), tweet.getText(), tweet.getGeoLocation()); } } catch (TwitterException te) { logger.error(te); logger.error("Failed to search tweets: " + te.getMessage()); System.exit(-1); } catch (ResourceInstantiationException ex) { logger.error(ex); } logger.info("corpus size" + corpus.size()); }
From source file:examples.GetFriendsIDs.java
License:Apache License
/** * Usage: java twitter4j.examples.friendsandfollowers.GetFriendsIDs [screen name] * * @param args message/* ww w . j av a 2 s . c o m*/ */ public static void main(String[] args) { try { Twitter twitter = CommonUtils.getTwitterInstance(); long cursor = -1; PagableResponseList<User> userList; System.out.println("Listing following ids."); do { userList = twitter.getFriendsList("tsantoo", cursor); for (User user : userList) { System.out.println(user.toString()); } } while ((cursor = userList.getNextCursor()) != 0); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get friends' ids: " + te.getMessage()); System.exit(-1); } }
From source file:examples.GetRateLimitStatus.java
License:Apache License
public static void main(String[] args) { try {/*from w ww. j av a 2 s. c om*/ Twitter twitter = CommonUtils.getTwitterInstance(); Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus(); for (String endpoint : rateLimitStatus.keySet()) { RateLimitStatus status = rateLimitStatus.get(endpoint); if (endpoint.equals("/users/lookup")) { System.out.println("Endpoint: " + endpoint); System.out.println(" Limit: " + status.getLimit()); System.out.println(" Remaining: " + status.getRemaining()); System.out.println(" ResetTimeInSeconds: " + status.getResetTimeInSeconds()); System.out.println(" SecondsUntilReset: " + status.getSecondsUntilReset()); } } System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get rate limit status: " + te.getMessage()); System.exit(-1); } }
From source file:examples.GetUserListStatuses.java
License:Apache License
/** * Usage: java twitter4j.examples.list.GetUserListStatuses [list id] * * @param args message/*from ww w . ja v a 2s. c om*/ */ public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.list.GetUserListStatuses [list id]"); System.exit(-1); } try { Twitter twitter = new TwitterFactory().getInstance(); Paging page = new Paging(1); ResponseList<Status> statuses; do { statuses = twitter.getUserListStatuses(Integer.parseInt(args[0]), page); for (Status status : statuses) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } page.setPage(page.getPage() + 1); } while (statuses.size() > 0 && page.getPage() <= 10); System.out.println("done."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to list statuses: " + te.getMessage()); System.exit(-1); } }
From source file:fr.istic.taa.jaxrs.TweetEndpoint.java
License:Apache License
@GET @Path("/status") @Produces(MediaType.TEXT_PLAIN)/*from ww w . jav a 2 s . c o m*/ public String getStatus() { try { String result_l = ""; for (Status status_l : link.getHomeTimeline()) { result_l += status_l.getText() + "\n"; } return result_l; } catch (TwitterException e) { logger.error(e.getMessage(), e); } return "Erreur lors de la rcupration des tweets"; }
From source file:fr.istic.taa.jaxrs.TweetEndpoint.java
License:Apache License
@POST @Path("/post") @Consumes(MediaType.TEXT_PLAIN)//from w ww.ja v a2s . co m @Produces(MediaType.TEXT_PLAIN) public String sendTweet(String status) { try { link.updateStatus(status); return "Tweeted Successfully"; } catch (TwitterException e) { logger.error("Erreur lors du postage de tweet : " + e.getMessage(), e); } return "An error occured"; }
From source file:fr.istic.taa.jaxrs.TweetEndpoint.java
License:Apache License
@POST @Path("/send") @Consumes(MediaType.TEXT_PLAIN)/*from ww w .j a v a2s .co m*/ @Produces(MediaType.TEXT_PLAIN) public String sendMessage(String status) { try { String[] split = status.split(":"); link.sendDirectMessage(split[0], split[1]); return "Tweeted Successfully"; } catch (TwitterException e) { logger.error("Erreur lors de l'envoi du message : " + e.getMessage(), e); } return "An error occured"; }
From source file:fr.istic.taa.jaxrs.TweetEndpoint.java
License:Apache License
@GET @Path("/friends/{id}") @Produces(MediaType.TEXT_PLAIN)//from w w w . j a va2s . c o m public String getFriends(@PathParam("id") String id) { String result = ""; long cursor = -1; PagableResponseList<User> list_l; try { do { list_l = link.getFriendsList(id, cursor); for (User user_l : list_l) { result += user_l.getName() + "\n"; } } while ((cursor = list_l.getNextCursor()) != 0); } catch (TwitterException e) { logger.error(e.getMessage(), e); } return result; }