List of usage examples for twitter4j TwitterException getMessage
@Override
public String getMessage()
From source file:com.SocialAccess.TwitterSearch.java
public static String[] FriendshipStatus(String[] args) { if (args.length < 2) { System.out.println("Usage: [source screen name] [target screen name]"); System.exit(-1);//from w ww .ja v a 2 s . c om } String[] lineConnection = new String[2]; try { Twitter twitter = new TwitterFactory().getInstance(); Relationship relationship = twitter.showFriendship(args[0], args[1]); lineConnection[0] = args[0] + " is followed by " + args[1] + " " + relationship.isSourceFollowedByTarget(); lineConnection[1] = args[0] + " is following " + args[1] + " " + relationship.isSourceFollowingTarget(); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to show friendship: " + te.getMessage()); System.exit(-1); } return lineConnection; }
From source file:com.speed.traquer.app.TraqComplaintTaxi.java
private void checkTwitterID() { /* Get Access Token after login*/ try {// w w w . j a v a 2 s . c o m ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY); builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET); // Access Token String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, ""); // Access Token Secret String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, ""); AccessToken accessToken = new AccessToken(access_token, access_token_secret); Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken); // Getting user details from twitter // For now i am getting his name only twitterID = accessToken.getUserId(); User user = twitter.showUser(twitterID); userName = user.getName(); //Toast.makeText(TraqComplaintTaxi.this, Long.toString(twitterID) + userName, Toast.LENGTH_SHORT).show(); // Displaying in xml ui //lblUserName.setText(Html.fromHtml("<b>Welcome " + username + "</b>" + description)); } catch (TwitterException e) { // Error in updating status Log.d("Twitter Update Error", e.getMessage()); } catch (Exception e) { // Error in updating status Log.d("error!", e.getMessage()); } }
From source file:com.test.GetDirectMessages.java
License:Apache License
/** * Usage: java twitter4j.examples.directmessage.GetDirectMessages * * @param args String[]//from ww w . ja v a 2 s. com */ public static void main(String[] args) { // Twitter twitter = new TwitterFactory().getInstance(); Twitter twitter = AccountTwitterFactory.getWiseManTwitter(); try { Paging paging = new Paging(1); List<DirectMessage> messages; do { messages = twitter.getDirectMessages(paging); for (DirectMessage message : messages) { System.out.println("From: @" + message.getSenderScreenName() + " id:" + message.getId() + " - " + message.getText()); } paging.setPage(paging.getPage() + 1); } while (messages.size() > 0 && paging.getPage() < 10); System.out.println("done."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get messages: " + te.getMessage()); System.exit(-1); } }
From source file:com.tuncaysenturk.jira.plugins.compatibility.servlet.TwitterLoginServlet.java
public void login(HttpServletRequest req, HttpServletResponse resp, Map<String, Object> context) { Twitter twitter = new TwitterFactory().getInstance(); try {/* w ww. j a v a 2 s. c om*/ PropertySet propSet = ComponentManager.getComponent(PropertiesManager.class).getPropertySet(); URI servletConfigureTwitter = URI .create(applicationProperties.getBaseUrl() + JTPConstants.URL_CONFIGURE_TWITTER); String callbackURL = servletConfigureTwitter + QUESTION_MARK + IS_CALLBACK + EQUALS + TRUE; twitter.setOAuthConsumer(propSet.getString("consumerKey"), propSet.getString("consumerSecret")); RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL); String requestToken_token = requestToken.getToken(); String requestToken_secret = requestToken.getTokenSecret(); propSet.setString("requestToken", requestToken_token); propSet.setString("requestTokenSecret", requestToken_secret); String redirectUrl = requestToken.getAuthorizationURL(); resp.sendRedirect(redirectUrl); } catch (TwitterException e) { logger.error(JTPConstants.LOG_PRE + "Exception while logging to Twitter", e); @SuppressWarnings("unchecked") List<String> errorMessages = (List<String>) context.get("errorMessages"); errorMessages.add(e.getMessage()); } catch (IOException e) { logger.error(JTPConstants.LOG_PRE + "Exception while logging to Twitter", e); } }
From source file:com.tweet.analysis.SearchTweets.java
License:Apache License
/** * Usage: java twitter4j.examples.search.SearchTweets [query] * * @param args search query/*from w ww. j a va 2 s .com*/ */ public static void main(String[] args) { if (args.length < 1) { //System.out.println("java twitter4j.examples.search.SearchTweets [query]"); //System.exit(-1); } Twitter twitter = new TwitterFactory().getInstance(); //twitter.getFollowersList("Kuldeep.loveiit"); try { Query query = new Query("Modi"); QueryResult result; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); } } while ((query = result.nextQuery()) != null); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); System.exit(-1); } }
From source file:com.varaneckas.hawkscope.plugins.twitter.TwitterPlugin.java
License:Open Source License
/** * Handles {@link TwitterException}.//from w ww . j a v a2s .c o m * * @param e */ private void handleTwitterException(final TwitterException e) { if (e.getMessage().startsWith("Server")) { twitterError = "Server error"; } else { twitterError = "Network error"; } log.warn("Twitter error", e); createTwitter(ConfigurationFactory.getConfigurationFactory().getConfiguration()); }
From source file:com.vodafone.twitter.service.TwitterService.java
License:Apache License
private int fetchHomeTimeline() { // retrieve the latest up to maxQueueMessages twt-msgs int count = 0, countProcessed = 0; if (twitter != null) { List<Status> statuses = null; try {/*from w ww .j av a 2s . c o m*/ int messageListSize = 0; Paging paging = new Paging(); paging.setCount(maxQueueMessages); if (Config.LOGD) Log.i(LOGTAG, String.format("fetchHomeTimeline() twitter.getHomeTimeline() maxQueueMessages=%d", maxQueueMessages)); statuses = twitter.getHomeTimeline(paging); if (statuses != null) { count = statuses.size(); for (Status status : statuses) { if (processStatus(status)) countProcessed++; } synchronized (messageList) { messageListSize = messageList.size(); } if (Config.LOGD) Log.i(LOGTAG, String.format("fetchHomeTimeline() countProcessed=%d, messageList.size()=%d done", countProcessed, messageListSize)); if (countProcessed > 0) notifyClient(); } else { if (Config.LOGD) Log.i(LOGTAG, "fetchHomeTimeline() no statuses"); } } catch (TwitterException twex) { Log.e(LOGTAG, "fetchHomeTimeline() failed to get twitter timeline: " + twex); errMsg = twex.getMessage(); } catch (java.lang.IllegalStateException illstaex) { Log.e(LOGTAG, "fetchHomeTimeline() IllegalStateException illstaex=" + illstaex); errMsg = "IllegalStateException on .getHomeTimeline()"; } } return count; }
From source file:com.wimbli.serverevents.Register.java
License:Open Source License
private static void execute() { try {/*from ww w.j a v a 2 s .co m*/ ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("QyuUqx8UFaRLMWORQinphg") .setOAuthConsumerSecret("EWORHYNo3JkJgvihiGwFL8tWNHExyhWFilR1Q"); twitter = new TwitterFactory(cb.build()).getInstance(); accessToken = null; try { // get request token. // this will throw IllegalStateException if access token is already available requestToken = twitter.getOAuthRequestToken(); msg("Open the following URL and grant access to ServerEvents:"); msg(requestToken.getAuthorizationURL()); outputToFile("Open the following URL and grant access to ServerEvents: \n" + requestToken.getAuthorizationURL()); msg("For convenience, this URL has also been output to a file: " + outFile); if (cmdLine) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (null == accessToken) { System.out.print( "Enter the PIN(if available) and hit enter after you have granted access. [PIN]:"); String pin = br.readLine(); tryPin(pin); } } } catch (IllegalStateException ie) { // access token is already available, or consumer key/secret is not set. if (!twitter.getAuthorization().isEnabled()) { msg("OAuth consumer key/secret is not set."); exit(-1); } } } catch (TwitterException te) { msg("Failed to get timeline: " + te.getMessage()); msg("Try revoking access to the ServerEvents application from your Twitter settings page."); exit(-1); } catch (IOException ioe) { msg("Failed to read the system input."); exit(-1); } if (cmdLine) exit(0); }
From source file:crawling.FoundUsersBySearchGeo.java
License:Apache License
public static void main(String[] args) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { /* my shutdown code here */ // Record the user status out.println("Final status -------------------:"); for (Long id : discoveredUsers.keySet()) { out.println(id + "," + discoveredUsers.get(id)); }//from www .ja va2s . c o m out.close(); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = new Date(); date = new Date(); System.out.println("End at: " + dateFormat.format(date)); } }); if (args.length < 5) { System.out.println("Usage: java twitter4j.examples.PrintFilterStreamGeo lati long radius unit CITY"); System.exit(-1); } if (args.length == 6) { // Preload the collected user IDs preloadID(args[5]); } try { FileWriter outFile = new FileWriter("discoveredUser" + args[4] + ".txt", true); out = new PrintWriter(outFile); //out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } avgUsers = new int[histCount]; Query query = new Query(); query.setGeoCode(new GeoLocation(Double.parseDouble(args[0]), Double.parseDouble(args[1])), Double.parseDouble(args[2]), args[3]); // New York Metropolitan //query.setGeoCode(new GeoLocation(40.7, -74), 100, "km"); // Bay Area MetroPolitan //query.setGeoCode(new GeoLocation(37.78, -122.4), 100, "km"); // LA MetroPolitan //query.setGeoCode(new GeoLocation(34.05, -118.24), 200, "km"); query.setCount(100); //query.setPage(20); //Twitter twitter = new TwitterFactory().getInstance(); Twitter twitter = getOAuthTwitter(); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = new Date(); //System.out.println(); System.out.println("----------------------------------------------"); System.out.println("Start at: " + dateFormat.format(date)); while (true) { //for (int i = 1; i <= 15; i ++){ // query.setPage(i); try { doASearch(twitter, query); } catch (TwitterException te) { // TODO Auto-generated catch block te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); // back-off Thread.currentThread(); try { Thread.sleep(60 * 1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Thread.currentThread(); try { Thread.sleep(5 * 1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:crawling.FoundUsersBySearchHashtag.java
License:Apache License
public static void main(String[] args) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { /* my shutdown code here */ // Record the user status out.println("Final status -------------------:"); for (Long id : discoveredUsers.keySet()) { out.println(id + "," + discoveredUsers.get(id)); }// ww w.jav a 2 s . c o m out.close(); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = new Date(); date = new Date(); System.out.println("End at: " + dateFormat.format(date)); } }); if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.PrintFilterStreamHashtag hashtag"); System.exit(-1); } if (args.length == 2) { // Preload the collected user IDs preloadID(args[1]); } try { FileWriter outFile = new FileWriter("discoveredUser" + args[0] + ".txt", true); out = new PrintWriter(outFile); hashtag = args[0]; //out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } avgUsers = new int[histCount]; Query query = new Query(); //query.setGeoCode(new GeoLocation(Double.parseDouble(args[0]) // , Double.parseDouble(args[1])), Double.parseDouble(args[2]), args[3]); query.setQuery(hashtag); // New York Metropolitan //query.setGeoCode(new GeoLocation(40.7, -74), 100, "km"); // Bay Area MetroPolitan //query.setGeoCode(new GeoLocation(37.78, -122.4), 100, "km"); // LA MetroPolitan //query.setGeoCode(new GeoLocation(34.05, -118.24), 200, "km"); query.setCount(100); //query.setPage(20); //Twitter twitter = new TwitterFactory().getInstance(); Twitter twitter = getOAuthTwitter(); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = new Date(); //System.out.println(); System.out.println("----------------------------------------------"); System.out.println("Start at: " + dateFormat.format(date)); while (true) { //for (int i = 1; i <= 15; i ++){ // query.setPage(i); try { doASearch(twitter, query); } catch (TwitterException te) { // TODO Auto-generated catch block te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); // back-off Thread.currentThread(); try { Thread.sleep(60 * 1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Thread.currentThread(); try { Thread.sleep(5 * 1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }