List of usage examples for twitter4j Status getUser
User getUser();
From source file:kerguelenpetrel.RespondServlet.java
License:Apache License
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { StringBuilder builder = new StringBuilder(); resp.setContentType("text/plain; charset=UTF-8"); try {/* w w w .j a va 2 s . c o m*/ //Get the Twitter object Twitter twit = TwitterFactory.getSingleton(); ResponseList<Status> mentions = twit.getMentionsTimeline(); lastPostIdEntity = datastore.get(KeyFactory.createKey("lastPostIDEntity", "ID")); lastPostId = Long.parseLong(lastPostIdEntity.getProperty("lastPostID").toString()); if (mentions.size() == 0) { resp.getWriter().println("No mentions so far...\n"); return; } for (Status mention : mentions) { if (lastPostId < mention.getId()) { if (mention.getUser().getId() == twit.getId()) ; //don't respond to myself else if (mention.isRetweeted()) mention = twit.createFavorite(mention.getId()); //mark the retweet as a favourite else if (mention.getText().toLowerCase().contains("bye")) { builder.setLength(0); builder.append("@"); builder.append(mention.getUser().getScreenName()); builder.append(" Bye"); } else { builder.setLength(0); //Add the screen name of the person we are responding to builder.append("@"); builder.append(mention.getUser().getScreenName() + " "); //Get feed title as content builder.append(getFeedTitle(resp)); //Get a Wordnik trend builder.append(getWordnikTrend(resp)); /* Tweets are maximum 280 characters */ if (builder.length() > 280) { builder.setLength(builder.lastIndexOf(" ", 270)); builder.append(end[(r.nextInt(end.length))]); } } //Set the status StatusUpdate status = new StatusUpdate(builder.toString()); //Post the status twit.updateStatus(status); resp.getWriter().println("Tweet posted: " + status.getStatus()); } } //Save last post ID lastPostIdEntity.setProperty("lastPostID", (Long.toString(mentions.get(0).getId()))); datastore.put(lastPostIdEntity); } catch (EntityNotFoundException e) { // Make new ResponseIDentity lastPostIdEntity = new Entity("lastPostIDEntity", "ID"); lastPostIdEntity.setProperty("lastPostID", "0"); datastore.put(lastPostIdEntity); resp.getWriter() .println("Made new lastPostId " + lastPostIdEntity.getProperty("lastPostID").toString()); } catch (TwitterException e) { resp.getWriter().println("Problem with Twitter \n"); e.printStackTrace(resp.getWriter()); } }
From source file:kr.debop4j.search.twitter.Twitters.java
License:Apache License
public static Twit createTwit(Status status) { Twit twit = new Twit(); twit.setId(status.getId());/*from w w w . j a v a 2 s.c om*/ twit.setUsername(status.getUser().getName()); twit.setText(status.getText()); twit.setCreatedAt(status.getCreatedAt()); return twit; }
From source file:libreriatwitter.Metodos.java
/** * Muestra el timeline/*from ww w . ja v a 2s . co m*/ * @throws twitter4j.TwitterException */ public void verTimeLine() throws TwitterException { ResponseList<twitter4j.Status> statuses = twitter.getHomeTimeline(); System.out.println("Showing home timeline."); for (twitter4j.Status status : statuses) { System.out.println(status.getUser().getName() + ":" + status.getText()); } }
From source file:libreriatwitter.Metodos.java
/** * Buscador de Tweets/* www . j a v a 2 s . com*/ * @param buscar * @throws twitter4j.TwitterException */ public void buscarTweet(String buscar) throws TwitterException { Query query = new Query(buscar); QueryResult result = twitter.search(query); for (twitter4j.Status status : result.getTweets()) { System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); } }
From source file:Logic.mongoC.java
public boolean inicioSesion() { /*Entro a twitter con una cuenta de un suario x para esto necesite los permisos que esta abajo*/ /*Permisos de la cuenta a la que ingreso*/ /*Trata de hacer la conexion con twitter y toma los ultimos 20 twitts que aparecen en la time line del usuario*///from w w w. java2 s. co m conect(); try { twitter4j.User user = twitter.verifyCredentials(); List<Status> statu = twitter.getHomeTimeline(); for (Status sta : statu) { System.out.println("Showing @" + sta.getUser().getScreenName() + "->" + sta.getText()); } //usuario("sofimelgar_",cb,twitter); return true; } catch (TwitterException ex) { return false; } }
From source file:Logic.mongoC.java
public void IngresarUsuario(String name) { String[] buscarUs = new String[1]; buscarUs[0] = name;// w w w .ja va 2 s . c o m try { ResponseList<twitter4j.User> use = twitter.lookupUsers(buscarUs); twitter4j.User u = use.get(0); System.out.println(u.getStatus()); usuario nuevoS = new usuario(); nuevoS.setId(Long.toString(u.getId())); nuevoS.setNombre(u.getName()); nuevoS.setLocation(u.getLocation()); nuevoS.setNumFol(u.getFollowersCount()); nuevoS.setNumeroDeT(u.getStatusesCount()); List<Status> twitts = twitter.getUserTimeline(u.getId(), new Paging(1, 200)); ArrayList<twitt> timeL = new ArrayList(); for (Status s : twitts) { twitt tw = new twitt(); tw.setTexto(s.getText()); tw.setRetwett(s.getRetweetCount()); //tw.setFecha((java.util.Date) s.getCreatedAt()); tw.setFav(s.getFavoriteCount()); tw.setCreador(s.getUser().getScreenName()); UserMentionEntity[] userMentionEntities = s.getUserMentionEntities(); ArrayList<String> inter = new ArrayList(); for (UserMentionEntity uh : userMentionEntities) { inter.add(uh.getScreenName()); } tw.setPersonas(inter); timeL.add(tw); } nuevoS.setTimeline(timeL); final String fIns = gson.toJson(nuevoS); Document dt; dt = new Document("ScreenName", u.getScreenName()); dt.append("todo", fIns); conect(); coll.insertOne(dt); JOptionPane.showMessageDialog(null, "Usuario Ingresado"); } catch (TwitterException ex) { System.out.println("No se pudo conectar el usuario deseado"); } }
From source file:main.TwitterController.java
License:Open Source License
public void listMentions() throws TwitterException { int counter = 0; List<Status> mentions = twitter.getMentions(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); Iterator<Status> iterator = mentions.iterator(); while (iterator.hasNext()) { Status s = iterator.next(); System.out.println(++counter + " [" + s.getCreatedAt().toString() + "] " + printUser(s.getUser()) + ": " + s.getText());// w w w .j av a 2 s . c o m if (counter % 10 == 0) { System.out.print("Hit [Enter] to continue, or type q to break: "); String str = null; try { str = in.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (str.length() > 0 && (str.charAt(0) == 'Q' || str.charAt(0) == 'q')) return; } } }
From source file:main.TwitterController.java
License:Open Source License
public void getTimeline() throws TwitterException { List<Status> statusList = null; int counter = 0; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); statusList = twitter.getFriendsTimeline(); Iterator<Status> iterator = statusList.iterator(); while (iterator.hasNext()) { Status s = iterator.next(); System.out.println(++counter + " [" + s.getCreatedAt().toString() + "] " + printUser(s.getUser()) + ": " + s.getText());//from w ww . j a v a 2 s.co m if (counter % 10 == 0) { System.out.print("Hit [Enter] to continue, or type q to break: "); String str = null; try { str = in.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (str.length() > 0 && (str.charAt(0) == 'Q' || str.charAt(0) == 'q')) return; } } }
From source file:MainScreen.Display.java
/** * Displays the 5 most recent tweets from the established twitter account * link onto their respective jLabels (in chronological order). * * @throws TwitterException/*w w w. j a v a 2 s . c o m*/ */ public void displayTweets() throws TwitterException { System.out.println("Showing home timeline."); int currentYear = Calendar.getInstance().get(Calendar.YEAR); try { setTwitPic(); } catch (IOException ex) { Logger.getLogger(Display.class.getName()).log(Level.SEVERE, null, ex); } for (Status status : statuses) { if (status.getText().contains(Integer.toString(currentYear))) { returnNumber(statuses.indexOf(status)) .setText("Picture tweet! Check the twitter for announcements!"); } else { returnNumber(statuses.indexOf(status)).setText("<html>@<b>" + status.getUser().getScreenName() + "</b> - <i>" + status.getUser().getName() + "</i>: <br>" + status.getText() + "</html>"); } } }
From source file:me.timothy.twittertoreddit.TwitterToReddit.java
License:Open Source License
public void postTweet(Status status) { if (status.getUser().getId() != twitterId) return;/*from www. j av a 2 s. c om*/ String text = status.getText(); // Find the first hyperlink System.out.println(status.getUser().getName() + " - " + text); Matcher matcher = URL_PATTERN.matcher(text); if (matcher.find()) { String firstLink = matcher.group(); System.out.println(" Link: " + firstLink); firstLink = LinkUnshortener.unshorten(restClient, firstLink); System.out.println(" Unshortened: " + firstLink); String realText = text.substring(0, matcher.start()).trim(); try { redditUser.submitLink(realText, firstLink, subreddit); } catch (IOException | ParseException e) { e.printStackTrace(); System.exit(1); } } else { System.out.println(" Failed to find link"); } }