List of usage examples for twitter4j TwitterException getMessage
@Override
public String getMessage()
From source file:gui.project2.v1.FXMLDocumentController.java
@FXML public void searchloaction() throws InterruptedException { int maxFollowerCount = 0; userslocations = new ArrayList<>(); nodes = new ArrayList<>(); GraphicsContext gc = graph.getGraphicsContext2D(); gc.setFill(Color.GAINSBORO);/*from ww w . jav a 2s . c om*/ gc.fillRect(0, 0, 308, 308); Twitter twitter; twitter = tf.getInstance(); ArrayList<User> users = new ArrayList<>(); try { Query query = new Query(""); GeoLocation location; location = new GeoLocation(parseDouble(latitude.getText()), parseDouble(longitude.getText())); Query.Unit unit = Query.KILOMETERS; query.setGeoCode(location, parseDouble(radius.getText()), unit); QueryResult result; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); boolean q = false; if (userslocations != null && !userslocations.isEmpty()) { for (int i = 0; i < userslocations.size(); i++) { if (userslocations.get(i).getName().equals(tweet.getUser().getScreenName())) { q = true; break; } } } if (!q && tweet.getGeoLocation() != null) { pair n; String latString = ""; String lonString = ""; int la = 0; int lo = 0; String geoString = tweet.getGeoLocation().toString(); for (int i = 0; i < geoString.length(); i++) { if (geoString.charAt(i) == '=') { if (la == 0) { la = 1; } else if (la == -1) { lo = 1; } } else if (geoString.charAt(i) == ',') { la = -1; } else if (geoString.charAt(i) == '}') { lo = -1; } else if (la == 1) { latString = latString + geoString.charAt(i); } else if (lo == 1) { lonString = lonString + geoString.charAt(i); } } User thisUser; thisUser = tweet.getUser(); double lat = parseDouble(latString); double lon = parseDouble(lonString); System.out.println(tweet.getGeoLocation().toString()); n = new pair(tweet.getUser().getScreenName(), lat, lon); userslocations.add(n); users.add(thisUser); if (thisUser.getFollowersCount() > maxFollowerCount) { maxFollowerCount = thisUser.getFollowersCount(); } } } } while ((query = result.nextQuery()) != null); for (int i = 0; i < users.size(); i++) { if (i % 14 == 0 && i != 0) { Thread.sleep(1000 * 60 * 15 + 30); } IDs friends; friends = twitter.getFriendsIDs(users.get(i).getId(), -1); for (long j : friends.getIDs()) { for (int k = i + 1; k < users.size(); k++) { if (users.get(k).getId() == j) { nodes.add(users.get(i).getScreenName() + ":" + users.get(k).getScreenName()); } } } } } catch (TwitterException te) { System.out.println("Failed to search tweets: " + te.getMessage()); System.exit(-1); } double xmin; double xmax; double ymin; double ymax; xmin = userslocations.get(0).getA(); xmax = userslocations.get(0).getA(); ymin = userslocations.get(0).getB(); ymax = userslocations.get(0).getB(); for (int i = 1; i < userslocations.size(); i++) { if (xmin > userslocations.get(i).getA()) { xmin = userslocations.get(i).getA(); } if (xmax < userslocations.get(i).getA()) { xmax = userslocations.get(i).getA(); } if (ymin > userslocations.get(i).getB()) { ymin = userslocations.get(i).getB(); } if (ymax < userslocations.get(i).getB()) { ymax = userslocations.get(i).getB(); } } for (int i = 0; i < userslocations.size(); i++) { if (userslocations.get(i).getA() - xmin >= 0 && userslocations.get(i).getB() - ymin >= 0) { gc.setLineWidth(users.get(i).getFollowersCount() / maxFollowerCount * 3 + 1); gc.strokeOval((userslocations.get(i).getA() - xmin) / (xmax - xmin) * 300 + 4, (userslocations.get(i).getB() - ymin) / (ymax - ymin) * 300 + 4, 4, 4); } } ObservableList<String> usersLeftList = FXCollections.observableArrayList(); for (int i = 0; i < users.size() - 1; i++) { User k = null; for (int j = i + 1; j < users.size(); j++) { if (users.get(j).getFollowersCount() > users.get(i).getFollowersCount()) { k = users.get(i); users.set(i, users.get(j)); users.set(j, k); } } } for (int i = 0; i < users.size() / 5; i++) { usersLeftList.add(users.get(i).getScreenName() + " " + users.get(i).getFollowersCount()); } listView.setItems(usersLeftList); gc.setLineWidth(1); gc.setFill(Color.BLUE); for (int i = 0; i < nodes.size(); i++) { String user1 = ""; String user2 = ""; int p = 0; double x1 = 0; double x2 = 0; double y1 = 0; double y2 = 0; for (int j = 0; j < nodes.get(i).length(); j++) { if (nodes.get(i).charAt(j) == ':') { p = 1; } else if (p == 0) { user1 = user1 + nodes.get(i).charAt(j); } else if (p == 1) { user2 = user2 + nodes.get(i).charAt(j); } } for (int j = 0; j < userslocations.size(); j++) { if (userslocations.get(j).getName().equals(user1)) { x1 = (userslocations.get(j).getA() - xmin) / (xmax - xmin) * 300 + 6; y1 = (userslocations.get(j).getB() - ymin) / (ymax - ymin) * 300 + 6; } else if (userslocations.get(j).getName().equals(user2)) { x2 = (userslocations.get(j).getA() - xmin) / (xmax - xmin) * 300 + 6; y2 = (userslocations.get(j).getB() - ymin) / (ymax - ymin) * 300 + 6; } } gc.strokeLine(x1, y1, x2, y2); gc.fillOval(x1 - 2, y1 - 2, 4, 4); gc.fillOval(x2 - 2, y2 - 2, 4, 4); } }
From source file:hashimotonet.UpdateStatus.java
License:Apache License
/** * Usage: java twitter4j.examples.tweets.UpdateStatus [text] * /*from w ww . j av a2 s . c om*/ * @param args * message */ public static void main(String[] args) { /* try { new UpdateStatus().connectTwitter(); } catch(Exception e) { e.printStackTrace(); } */ if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.tweets.UpdateStatus [text]"); System.exit(-1); } String message = ""; for (int i = 0; i < args.length; i++) { message += args[i] + " "; } try { Twitter twitter = new TwitterFactory().getInstance(); try { // get request token. // this will throw IllegalStateException if access token is // already available RequestToken requestToken = twitter.getOAuthRequestToken(); // RequestToken requestToken = new RequestToken(Globals.KEY,Globals.SECRET); String url = requestToken.getAuthenticationURL(); System.out.println("url = " + url); 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()); 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()); } 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."); System.exit(-1); } } Status status = twitter.updateStatus(message); System.out.println("Successfully updated the status to [" + status.getText() + "]."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } catch (IOException ioe) { ioe.printStackTrace(); System.out.println("Failed to read the system input."); System.exit(-1); } }
From source file:info.usbo.skypetwitter.Run.java
License:Apache License
public static void main(String[] args) throws SkypeException, IOException { System.out.println("Working Directory = " + System.getProperty("user.dir")); Properties props = new Properties(); loadProperties(props, "twitter4j.properties"); loadProperties(props, "skype.properties"); loadProperties(props, "app.properties"); String chat_group_id = props.getProperty("skype.chat_group_id"); String twitter_user_id = props.getProperty("twitter.user"); data_dir = props.getProperty("data.dir"); Integer twitter_timeout = Integer.parseInt(props.getProperty("twitter.timeout")); System.out.println("Twitter user: " + twitter_user_id); System.out.println("Twitter timeout: " + twitter_timeout); if ("".equals(twitter_user_id)) { return;//from w w w .ja v a 2s . com } if (load_file() == 0) { System.out.println("File not found"); return; } while (true) { bChanged = 0; SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm"); System.out.println("Looking at " + sdf.format(Calendar.getInstance().getTime())); Chat ch = Skype.chat(chat_group_id); Twitter twitter = new TwitterFactory().getInstance(); try { List<Status> statuses; statuses = twitter.getUserTimeline(twitter_user_id); String sText; for (Status status : statuses) { Date d = status.getCreatedAt(); // ? Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(Calendar.HOUR_OF_DAY, 7); d = cal.getTime(); sText = "@" + status.getUser().getScreenName() + " " + sdf.format(d) + " ( https://twitter.com/" + twitter_user_id + "/status/" + status.getId() + " ): \r\n" + status.getText() + "\r\n***"; for (URLEntity e : status.getURLEntities()) { sText = sText.replaceAll(e.getURL(), e.getExpandedURL()); } for (MediaEntity e : status.getMediaEntities()) { sText = sText.replaceAll(e.getURL(), e.getMediaURL()); } if (twitter_ids.indexOf(status.getId()) == -1) { System.out.println(sText); ch.send(sText); twitter_ids.add(status.getId()); bChanged = 1; } } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); // System.exit(-1); } catch (SkypeException ex) { ex.printStackTrace(); System.out.println("Failed to send message: " + ex.getMessage()); } // VK try { vk(); for (VK v : vk) { if (vk_ids.indexOf(v.getId()) == -1) { Date d = v.getDate(); // ? Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(Calendar.HOUR_OF_DAY, 7); d = cal.getTime(); String sText = "@Depersonilized (VK) " + sdf.format(d) + " ( http://vk.com/Depersonilized?w=wall-0_" + v.getId() + " ): \r\n" + v.getText(); if (!"".equals(v.getAttachment())) { sText += "\r\n" + v.getAttachment(); } sText += "\r\n***"; System.out.println(sText); ch.send(sText); vk_ids.add(v.getId()); bChanged = 1; } } } catch (ParseException e) { e.printStackTrace(); System.out.println("Failed to get vk: " + e.getMessage()); // System.exit(-1); } catch (SkypeException ex) { ex.printStackTrace(); System.out.println("Failed to send message: " + ex.getMessage()); } if (bChanged == 1) { save_file(); } try { Thread.sleep(1000 * 60 * twitter_timeout); } catch (InterruptedException ex) { ex.printStackTrace(); System.out.println("Failed to sleep: " + ex.getMessage()); } } }
From source file:it.baywaylabs.jumpersumo.twitter.TwitterListener.java
License:Open Source License
/** * This method is called when invoke <b>execute()</b>.<br /> * Do not invoke manually. Use: <i>new TwitterListener().execute("");</i> * * @param params//from ww w . ja v a 2 s. co m */ @Override protected List<String> doInBackground(String... params) { Intelligence ai = new Intelligence(); try { User user = twitter.verifyCredentials(); Paging paging; if (idLastTwit != 0) paging = new Paging(idLastTwit + 1); else paging = new Paging(); paging.count(100); statuses = twitter.getMentionsTimeline(paging); if (statuses.size() != 0 && statuses != null) { Log.d(TAG, "Showing @" + user.getScreenName() + "'s mentions:"); Log.d(TAG, statuses.get(0).getText() + "-- ID: " + statuses.get(0).getId()); if (!"".equals(statuses.get(0).getText()) && licenses.size() == 0) { extractCommand(ai, statuses); Log.d(TAG, "Non ho licenze attive!"); } else if (!"".equals(statuses.get(0).getText()) && licenses.size() > 0 && f.boolContainsIgnoreCase(licenses, String.valueOf(statuses.get(0).getUser().getId()))) { extractCommand(ai, statuses); Log.i(TAG, "Seguo la lista delle licenze: " + licenses.toString()); } else { publishProgress(false); } if (deviceController != null) { Random r = new Random(); Interpreter interp = new Interpreter(deviceController); for (int i = 0; i < execute.size(); i++) { Log.d(TAG, "Seguenza istruzioni rilevate: " + execute.toString()); if (execute.size() >= 1 && "EXECUTE".equals(execute.get(i)) && f.getUrls(statuses.get(0).getText()).size() != 0) { String url = statuses.get(0).getURLEntities()[0].getExpandedURL(); // String url = f.getUrls(statuses.get(0).getText()).get(0); File folder = new File(Constants.DIR_ROBOT); Log.d(TAG, "URL Expanded: " + url); if (downloadFileUrl(url, folder)) { FileFilter ff = new FileFilter(); File[] list = folder.listFiles(ff); Log.e(TAG, "Lista file: " + list.length); if (list != null && list.length >= 1) { if (list[0].getName().endsWith(".csv") || list[0].getName().endsWith(".txt")) { String commandsList = ""; try { commandsList = f.getStringFromFile(list[0].getPath()); } catch (Exception e) { e.printStackTrace(); } Log.d(TAG, "Lista comandi: " + commandsList); interp.doListCommands(commandsList); list[0].delete(); if (i == execute.size() - 1) { try { StatusUpdate reply = new StatusUpdate( ai.actionAnswer(execute.get(i)).get( r.nextInt(ai.actionAnswer(execute.get(i)).size())) + "@" + statuses.get(0).getUser().getScreenName()); reply.setInReplyToStatusId(statuses.get(0).getId()); twitter.updateStatus(reply); } catch (TwitterException te) { Log.e(TAG, "Twitter Post Error: " + te.getMessage()); } } } } } } else if (execute.size() >= 1 && "PHOTO".equals(execute.get(i))) { // Download immagine e post nel tweet if (interp.doCommand(execute.get(i)) == 0) { String result = FTPDownloadFile(ip_host, 21, "anonymous", "", context); if (i == execute.size() - 1 && !"".equals(result)) { try { StatusUpdate reply = new StatusUpdate(ai.actionAnswer(execute.get(i)) .get(r.nextInt(ai.actionAnswer(execute.get(i)).size())) + "@" + statuses.get(0).getUser().getScreenName()); reply.setInReplyToStatusId(statuses.get(0).getId()); File image = new File(Constants.DIR_ROBOT_IMG + "/" + result); Log.d(TAG, "Nome File immagine: " + image.getPath()); reply.media(image); twitter.updateStatus(reply); image.delete(); } catch (TwitterException te) { Log.e(TAG, "Twitter Post Error: " + te.getMessage()); } } } } else if (execute.size() >= 1 && !"PHOTO".equals(execute.get(i)) && !"EXECUTE".equals(execute.get(i))) { if (interp.doCommand(execute.get(i)) == 0) { if (i == execute.size() - 1) { try { StatusUpdate reply = new StatusUpdate(ai.actionAnswer(execute.get(i)) .get(r.nextInt(ai.actionAnswer(execute.get(i)).size())) + "@" + statuses.get(0).getUser().getScreenName()); reply.setInReplyToStatusId(statuses.get(0).getId()); twitter.updateStatus(reply); } catch (TwitterException te) { Log.e(TAG, "Twitter Post Error: " + te.getMessage()); } } } } } } } Log.d(TAG, "ready exit"); } catch (TwitterException te) { te.printStackTrace(); Log.e(TAG, "Failed to get timeline: " + te.getMessage()); } return execute; }
From source file:it.baywaylabs.jumpersumo.utility.Finder.java
License:Open Source License
public int executePQ(PriorityQueue pq, ARDeviceController deviceController, List<twitter4j.Status> statuses, Twitter twitter) {/*from ww w . j av a 2 s .c o m*/ if (pq != null && !pq.isEmpty() && deviceController != null) { Interpreter interpreter = new Interpreter(deviceController); Intelligence ai = new Intelligence(); Random r = new Random(); int indexExecutedFile = 0; while (pq.isEmpty()) { Command c = (Command) pq.peek(); Log.d(TAG, "Command Object: " + c.getPriority() + " -- " + c.getCmd()); if ("EXECUTE".equals(c.getCmd())) { if (statuses != null && twitter != null && this.getUrls(statuses.get(0).getText()).size() != 0) { String url = statuses.get(0).getURLEntities()[indexExecutedFile].getExpandedURL(); // String url = f.getUrls(statuses.get(0).getText()).get(0); File folder = new File(Constants.DIR_ROBOT); Log.d(TAG, "URL Expanded: " + url); if (downloadFileUrl(url, folder)) { FileFilter ff = new FileFilter(); File[] list = folder.listFiles(ff); if (list != null && list.length >= 1) { if (list[0].getName().endsWith(".csv") || list[0].getName().endsWith(".txt")) { String commandsList = ""; try { commandsList = this.getStringFromFile(list[0].getPath()); } catch (Exception e) { e.printStackTrace(); } Log.d(TAG, "Lista comandi: " + commandsList); interpreter.doListCommands(commandsList); list[0].delete(); if (pq.size() == 1) { try { StatusUpdate reply = new StatusUpdate(ai .actionAnswer( commandsList.split(";")[commandsList.length() - 1]) .get(r.nextInt(ai.actionAnswer( commandsList.split(";")[commandsList.length() - 1]) .size())) + "@" + statuses.get(0).getUser().getScreenName()); reply.setInReplyToStatusId(statuses.get(0).getId()); twitter.updateStatus(reply); } catch (TwitterException te) { Log.e(TAG, "Twitter Post Error: " + te.getMessage()); } } } } } pq.remove(); indexExecutedFile++; } } else { interpreter.doCommand(c.getCmd()); pq.remove(); } } return 0; } else if (pq.isEmpty()) { return 2; } else { return 1; } }
From source file:jp.gihyo.wicket.AppSession.java
License:Apache License
public boolean login(String userName, String password) { Twitter client = new TwitterClient(userName, password); try {/*from w w w . ja v a2s .c om*/ User user = client.verifyCredentials(); if (user != null) { twitterUser = user; twitterSession = client; return true; } } catch (TwitterException ex) { if (ex.getStatusCode() == HttpServletResponse.SC_UNAUTHORIZED) { lastUnauthorizedMessage = ex.getMessage(); return false; } } return false; }
From source file:jp.ky.twittersample.UpdateStatus.java
License:Apache License
/** * Usage: java twitter4j.examples.tweets.UpdateStatus [text] * * @param args message//from w w w . ja v a 2s .c o m */ public static void main(String[] args) { // if (args.length < 1) { // System.out.println("Usage: java twitter4j.examples.tweets.UpdateStatus [text]"); // System.exit(-1); // } String message = "Test5"; try { Twitter twitter = new TwitterFactory().getInstance(); 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()); 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()); } 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."); System.exit(-1); } } //Status status = twitter.updateStatus(message); //System.out.println("Successfully updated the status to [" + status.getText() + "]."); AccountSettings as = twitter.getAccountSettings(); System.out.println("accountsettings:" + as.getScreenName()); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } catch (IOException ioe) { ioe.printStackTrace(); System.out.println("Failed to read the system input."); System.exit(-1); } }
From source file:jp.typosone.android.azarashi.AccessTokenTaskLoader.java
License:Apache License
@Override public AccessToken loadInBackground() { Uri uri = mIntent.getData();//from ww w . ja va2 s. com AccessToken token = null; if (uri != null && uri.toString().startsWith(mCallbackUrl)) { String verifier = uri.getQueryParameter("oauth_verifier"); try { token = mOAuth.getOAuthAccessToken(mRequestToken, verifier); } catch (TwitterException e) { Log.e(this.getClass().getPackage().getName(), e.getMessage(), e); } } return token; }
From source file:jp.typosone.android.azarashi.RequestTokenTaskLoader.java
License:Apache License
@Override public RequestToken loadInBackground() { mOAuth.setOAuthConsumer(getContext().getString(R.string.consumer_key), getContext().getString(R.string.consumer_secret)); RequestToken requestToken = null;/*from w ww.j ava 2 s . c o m*/ try { requestToken = mOAuth.getOAuthRequestToken(mCallbackUrl); } catch (TwitterException e) { Log.e(this.getClass().getPackage().getName(), e.getMessage(), e); } return requestToken; }
From source file:Jums.AllAPI.java
public int TweetCount(String word) { int i = 0;//from w w w. j av a 2 s . co m try { Query query = new Query(word); query.setCount(100); Date date = this.SetDate(); query.setSince(this.SetSDF()); QueryResult result = this.tw.search(query); for (Status status : result.getTweets()) { if (date.compareTo(status.getCreatedAt()) < 0) { i++; } } } catch (TwitterException te) { System.out.println(te.getMessage()); } catch (Exception e) { System.out.println(e.getMessage()); } return i; }