List of usage examples for twitter4j StatusUpdate StatusUpdate
public StatusUpdate(String status)
From source file:srss.core.TweetDialog.java
License:MIT License
public TweetDialog(final File screenshot) throws IOException { super(SRSS.getFrame(), ""); this.setAlwaysOnTop(true); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.setSize(600, 400); this.setResizable(false); this.setLocationRelativeTo(null); this.setLayout(null); ImageIcon image = new ImageIcon(ImageIO.read(screenshot)); this.pathl = new JLabel(image); JScrollPane imagePane = new JScrollPane(pathl); this.pathl.addKeyListener(this); this.pathl.addMouseListener(this); this.pathl.addMouseMotionListener(this); imagePane.setBounds(10, 10, 580, 300); this.getContentPane().add(imagePane); final JTextArea tweet = new JTextArea(1, 40); tweet.addKeyListener(this); JScrollPane scroll = new JScrollPane(tweet); scroll.setBounds(10, 320, 480, 40);//from w w w . jav a 2 s.com this.getContentPane().add(scroll); // this.button = new JButton(""); this.button.setBounds(500, 320, 80, 40); this.button.addKeyListener(this); this.button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { StatusUpdate status = new StatusUpdate(tweet.getText()); status.setMedia(screenshot); try { SRSS.getTwitterInstance().updateStatus(status); TweetDialog.this.dispose(); } catch (TwitterException e1) { e1.printStackTrace(); } } }); this.getContentPane().add(button); //------ this.setVisible(true); }
From source file:stemrps.MentionListener.java
License:Open Source License
@Override public void onStatus(Status status) { System.out.println(status.getUser().getScreenName() + ": " + status.getText()); String[] inp = status.getText().split(" "); String player = ""; if (inp[1].equalsIgnoreCase("stats")) { try {// w w w. j a v a 2s . co m long user = status.getUser().getId(); String whoStats = ""; if (inp.length >= 3) { if (inp[2] != null && !inp[2].equalsIgnoreCase("me")) { User acc = STEMrps.t.showUser(inp[2]); user = acc.getId(); whoStats = acc.getScreenName() + " "; } } String tweet = "@" + status.getUser().getScreenName() + " " + whoStats + GameLogic.getStatsString(user); STEMrps.t.updateStatus(tweet); } catch (Exception ex) { Logger.getLogger(MentionListener.class.getName()).log(Level.SEVERE, null, ex); return; } } else { try { if (status.getUser().getId() == 4741197613L) { //If it is our's? return; } STEMrps.makeSureUsrSetup(status.getUser().getId()); for (String s : inp) { if (STEMrps.getFromString(s) != null) { player = s; break; } } stemrps.GameResult match = STEMrps.playGame(status.getUser().getId(), player); String tweet = "@" + status.getUser().getScreenName() + " "; if (match == null) { tweet += "Something went wrong! Please use r, rock, p, paper, s, or scissors to play!"; } else if (match.outcome == stemrps.Status.W) { tweet += "You (" + match.player.name() + ") won against me (" + match.comp.name() + ")"; } else if (match.outcome == stemrps.Status.T) { tweet += "You (" + match.player.name() + ") tied against me (" + match.comp.name() + ")"; } else if (match.outcome == stemrps.Status.L) { tweet += "You (" + match.player.name() + ") lost against me (" + match.comp.name() + ")"; } tweet += " (Game #" + STEMrps.gamesPlayed() + ")"; StatusUpdate rt = new StatusUpdate(tweet); STEMrps.t.updateStatus(rt); } catch (Exception ex) { Logger.getLogger(MentionListener.class.getName()).log(Level.SEVERE, null, ex); String tweet = "@" + status.getUser().getScreenName() + " Oops, did't catch that. " + LocalDateTime.now(); StatusUpdate rt = new StatusUpdate(tweet); try { STEMrps.t.updateStatus(rt); } catch (TwitterException ex1) { Logger.getLogger(MentionListener.class.getName()).log(Level.SEVERE, null, ex1); } } } }
From source file:study.bot.TweetEngine.java
License:Open Source License
public void replyToARandomPerson() throws TwitterException { aRandomTweet = TweetsCreator.getARandomTweet("search"); query = new Query(TweetsCreator.searches.get(aRandomTweet)); result = twitter.search(query);//w w w .j ava 2 s.co m aRandomTweet = TweetsCreator.getARandomTweet("mention"); tweetResult = result.getTweets().get(aRandomTweet); aRandomTweet = TweetsCreator.getARandomTweet("reply"); statusUpdate = new StatusUpdate( ".@" + tweetResult.getUser().getScreenName() + TweetsCreator.replies.get(aRandomTweet)); statusUpdate.inReplyToStatusId(tweetResult.getId()); status = twitter.updateStatus(statusUpdate); }
From source file:testtweet.TweetUsingTwitter4jExample.java
/** * @param args the command line arguments *///w ww. j a v a 2s .c om public static void main(String[] args) throws IOException, TwitterException { //Instantiate a re-usable and thread-safe factory TwitterFactory twitterFactory = new TwitterFactory(Data.getConf().build()); //Instantiate a new Twitter instance Twitter twitter = twitterFactory.getInstance(); /* //setup OAuth Consumer Credentials twitter.setOAuthConsumer(consumerKey, consumerSecret); //setup OAuth Access Token twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret)); */ //Instantiate and initialize a new twitter status update StatusUpdate statusUpdate = new StatusUpdate( //your tweet or status message "Twitter API #Hacked"); //attach any media, if you want to /* statusUpdate.setMedia( //title of media "http://h1b-work-visa-usa.blogspot.com" , new URL("http://lh6.ggpht.com/-NiYLR6SkOmc/Uen_M8CpB7I/AAAAAAAAEQ8/tO7fufmK0Zg/h-1b%252520transfer%252520jobs%25255B4%25255D.png?imgmax=800").openStream()); */ //tweet or update status Status status = twitter.updateStatus(statusUpdate); //response from twitter server System.out.println("status.toString() = " + status.toString()); System.out.println("status.getInReplyToScreenName() = " + status.getInReplyToScreenName()); System.out.println("status.getSource() = " + status.getSource()); System.out.println("status.getText() = " + status.getText()); System.out.println("status.getContributors() = " + Arrays.toString(status.getContributors())); System.out.println("status.getCreatedAt() = " + status.getCreatedAt()); System.out.println("status.getCurrentUserRetweetId() = " + status.getCurrentUserRetweetId()); System.out.println("status.getGeoLocation() = " + status.getGeoLocation()); System.out.println("status.getId() = " + status.getId()); System.out.println("status.getInReplyToStatusId() = " + status.getInReplyToStatusId()); System.out.println("status.getInReplyToUserId() = " + status.getInReplyToUserId()); System.out.println("status.getPlace() = " + status.getPlace()); System.out.println("status.getRetweetCount() = " + status.getRetweetCount()); System.out.println("status.getRetweetedStatus() = " + status.getRetweetedStatus()); System.out.println("status.getUser() = " + status.getUser()); System.out.println("status.getAccessLevel() = " + status.getAccessLevel()); System.out.println("status.getHashtagEntities() = " + Arrays.toString(status.getHashtagEntities())); System.out.println("status.getMediaEntities() = " + Arrays.toString(status.getMediaEntities())); if (status.getRateLimitStatus() != null) { System.out .println("status.getRateLimitStatus().getLimit() = " + status.getRateLimitStatus().getLimit()); System.out.println( "status.getRateLimitStatus().getRemaining() = " + status.getRateLimitStatus().getRemaining()); System.out.println("status.getRateLimitStatus().getResetTimeInSeconds() = " + status.getRateLimitStatus().getResetTimeInSeconds()); System.out.println("status.getRateLimitStatus().getSecondsUntilReset() = " + status.getRateLimitStatus().getSecondsUntilReset()); System.out.println("status.getRateLimitStatus().getRemainingHits() = " + status.getRateLimitStatus().getRemaining()); } System.out.println("status.getURLEntities() = " + Arrays.toString(status.getURLEntities())); System.out.println("status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities())); }
From source file:toninbot.ToninStatusListener.java
@Override public void onStatus(Status tweetRecibido) { if (tweetRecibido.getUser().getId() != 184742273L && tweetRecibido.getUser().getId() != 2841338087L) { return;/* w w w .j a v a 2 s . co m*/ } System.out.println(tweetRecibido.getUser().getName() + " " + tweetRecibido.getText()); Calendar cal = Calendar.getInstance(); cal.setTime(tweetRecibido.getCreatedAt()); long hora = cal.get(Calendar.HOUR_OF_DAY); System.out.println("Hora: " + cal.get(Calendar.HOUR_OF_DAY)); //comprobar la hora if (hora > 7 || hora < 1) { return; } //comprobar que no sea una respuesta a alguien if (tweetRecibido.getText().contains("@")) { return; } StatusUpdate stat = new StatusUpdate( "@" + tweetRecibido.getUser().getScreenName() + " " + respuestaRandom()); System.out.println("Fora de horario!"); stat.inReplyToStatusId(tweetRecibido.getId()); try { twitter.updateStatus(stat); System.out.println("Twitteado: " + stat.toString()); } catch (TwitterException ex) { System.out.println("Error"); } }
From source file:twit.Twit.java
public static void onStatus(Status status, int kode) { Twitter tf = new TwitterFactory().getInstance(); //kode 1 : Format benar if (kode == 1) { StatusUpdate st = new StatusUpdate("Hi @" + status.getUser().getScreenName() + ", terima kasih telah membantu monitoring harga Cabe Indonesia :D"); st.inReplyToStatusId(status.getId()); try {//w w w. j a va 2s . co m tf.updateStatus(st); } catch (TwitterException e) { // TODO Auto-generated catch block e.printStackTrace(); } //kode 2 : Format salah } else if (kode == 2) { StatusUpdate st = new StatusUpdate( "Hi @" + status.getUser().getScreenName() + ", terima kasih atas laporan Anda! :)"); st.inReplyToStatusId(status.getId()); try { tf.updateStatus(st); } catch (TwitterException e) { // TODO Auto-generated catch block e.printStackTrace(); } //kode 2 : Format salah } else { System.out.println("error"); } }
From source file:twitter4j.examples.tweets.UploadMultipleImages.java
License:Apache License
/** * Usage: java twitter4j.examples.tweets.UploadMultipleImages [text] [file1] [file2] ... * * @param args message//from w w w. j ava 2 s.c o m */ public static void main(String[] args) { if (args.length < 1) { System.out.println( "Usage: java twitter4j.examples.tweets.UploadMultipleImages [text] [file1] [file2] ..."); System.exit(-1); } try { Twitter twitter = new TwitterFactory().getInstance(); long[] mediaIds = new long[args.length - 1]; for (int i = 1; i < args.length; i++) { System.out.println("Uploading...[" + i + "/" + (args.length - 1) + "][" + args[i] + "]"); UploadedMedia media = twitter.uploadMedia(new File(args[i])); System.out.println("Uploaded: id=" + media.getMediaId() + ", w=" + media.getImageWidth() + ", h=" + media.getImageHeight() + ", type=" + media.getImageType() + ", size=" + media.getSize()); mediaIds[i - 1] = media.getMediaId(); } StatusUpdate update = new StatusUpdate(args[0]); update.setMediaIds(mediaIds); Status status = twitter.updateStatus(update); System.out.println( "Successfully updated the status to [" + status.getText() + "][" + status.getId() + "]."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to update status: " + te.getMessage()); System.exit(-1); } }
From source file:twitterapidemo.TwitterAPIDemo.java
License:Apache License
public static void main(String[] args) throws IOException, TwitterException { //TwitterAPIDemo twitterApiDemo = new TwitterAPIDemo(); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(consumerKey); builder.setOAuthConsumerSecret(consumerSecret); Configuration configuration = builder.build(); TwitterFactory twitterFactory = new TwitterFactory(configuration); Twitter twitter = twitterFactory.getInstance(); twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret)); Scanner sc = new Scanner(System.in); System.out.println(/*from www. ja va2 s . c o m*/ "Enter your choice:\n1. To post tweet\n2.To search tweets\n3. Recent top 3 trends and number of posts of each trending topic"); int choice = sc.nextInt(); switch (choice) { case 1: System.out.println("What's happening: "); String post = sc.next(); StatusUpdate statusUpdate = new StatusUpdate(post + "-Posted by TwitterAPI"); Status status = twitter.updateStatus(statusUpdate); System.out.println("status.toString() = " + status.toString()); System.out.println("status.getInReplyToScreenName() = " + status.getInReplyToScreenName()); System.out.println("status.getSource() = " + status.getSource()); System.out.println("status.getText() = " + status.getText()); System.out.println("status.getContributors() = " + Arrays.toString(status.getContributors())); System.out.println("status.getCreatedAt() = " + status.getCreatedAt()); System.out.println("status.getCurrentUserRetweetId() = " + status.getCurrentUserRetweetId()); System.out.println("status.getGeoLocation() = " + status.getGeoLocation()); System.out.println("status.getId() = " + status.getId()); System.out.println("status.getInReplyToStatusId() = " + status.getInReplyToStatusId()); System.out.println("status.getInReplyToUserId() = " + status.getInReplyToUserId()); System.out.println("status.getPlace() = " + status.getPlace()); System.out.println("status.getRetweetCount() = " + status.getRetweetCount()); System.out.println("status.getRetweetedStatus() = " + status.getRetweetedStatus()); System.out.println("status.getUser() = " + status.getUser()); System.out.println("status.getAccessLevel() = " + status.getAccessLevel()); System.out.println("status.getHashtagEntities() = " + Arrays.toString(status.getHashtagEntities())); System.out.println("status.getMediaEntities() = " + Arrays.toString(status.getMediaEntities())); if (status.getRateLimitStatus() != null) { System.out.println( "status.getRateLimitStatus().getLimit() = " + status.getRateLimitStatus().getLimit()); System.out.println("status.getRateLimitStatus().getRemaining() = " + status.getRateLimitStatus().getRemaining()); System.out.println("status.getRateLimitStatus().getResetTimeInSeconds() = " + status.getRateLimitStatus().getResetTimeInSeconds()); System.out.println("status.getRateLimitStatus().getSecondsUntilReset() = " + status.getRateLimitStatus().getSecondsUntilReset()); } System.out.println("status.getURLEntities() = " + Arrays.toString(status.getURLEntities())); System.out.println( "status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities())); break; case 2: System.out.println("Enter keyword"); String keyword = sc.next(); try { Query query = new Query(keyword); QueryResult result; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { System.out.println(tweet.getCreatedAt() + ":\t@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); } } while ((query = result.nextQuery()) != null); System.exit(0); } catch (TwitterException te) { System.out.println("Failed to search tweets: " + te.getMessage()); System.exit(-1); break; } case 3: //WOEID for India = 23424848 Trends trends = twitter.getPlaceTrends(23424848); int count = 0; for (Trend trend : trends.getTrends()) { if (count < 3) { Query query = new Query(trend.getName()); QueryResult result; int numberofpost = 0; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { numberofpost++; } } while ((query = result.nextQuery()) != null); System.out .println("Number of post for the topic '" + trend.getName() + "' is: " + numberofpost); count++; } else break; } break; default: System.out.println("Invalid input"); } }
From source file:twitterswingclient.TwitterClient.java
private void updateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateActionPerformed // TODO add your handling code here: String consKey = "Your key"; String consSecret = "Your secret"; String accToken = "Your key"; String accSecret = "Your secret"; try {/*ww w . j a v a 2 s. com*/ TwitterFactory twitterFactory = new TwitterFactory(); Twitter twitter = twitterFactory.getInstance(); twitter.setOAuthConsumer(consKey, consSecret); twitter.setOAuthAccessToken(new AccessToken(accToken, accSecret)); StatusUpdate statusUpdate = new StatusUpdate(status.getText()); statusUpdate.setMedia("Feeling great", new URL("http://media3.giphy.com/media/el1tH0BzEWm4w/giphy.gif").openStream()); Status stat = twitter.updateStatus(statusUpdate); textArea.append("status.toString() = " + stat.toString()); textArea.append("status.getInReplyToScreenName() = " + stat.getInReplyToScreenName()); textArea.append("status.getSource() = " + stat.getSource()); textArea.append("status.getText() = " + stat.getText()); textArea.append("status.getContributors() = " + Arrays.toString(stat.getContributors())); textArea.append("status.getCreatedAt() = " + stat.getCreatedAt()); textArea.append("status.getCurrentUserRetweetId() = " + stat.getCurrentUserRetweetId()); textArea.append("status.getGeoLocation() = " + stat.getGeoLocation()); textArea.append("status.getId() = " + stat.getId()); textArea.append("status.getInReplyToStatusId() = " + stat.getInReplyToStatusId()); textArea.append("status.getInReplyToUserId() = " + stat.getInReplyToUserId()); textArea.append("status.getPlace() = " + stat.getPlace()); textArea.append("status.getRetweetCount() = " + stat.getRetweetCount()); textArea.append("status.getRetweetedStatus() = " + stat.getRetweetedStatus()); textArea.append("status.getUser() = " + stat.getUser()); textArea.append("status.getAccessLevel() = " + stat.getAccessLevel()); textArea.append("status.getHashtagEntities() = " + Arrays.toString(stat.getHashtagEntities())); textArea.append("status.getMediaEntities() = " + Arrays.toString(stat.getMediaEntities())); if (stat.getRateLimitStatus() != null) { textArea.append("status.getRateLimitStatus().getLimit() = " + stat.getRateLimitStatus().getLimit()); textArea.append( "status.getRateLimitStatus().getRemaining() = " + stat.getRateLimitStatus().getRemaining()); textArea.append("status.getRateLimitStatus().getResetTimeInSeconds() = " + stat.getRateLimitStatus().getResetTimeInSeconds()); textArea.append("status.getRateLimitStatus().getSecondsUntilReset() = " + stat.getRateLimitStatus().getSecondsUntilReset()); textArea.append("status.getRateLimitStatus().getRemainingHits() = " + stat.getRateLimitStatus().getRemaining()); } textArea.append("status.getURLEntities() = " + Arrays.toString(stat.getURLEntities())); textArea.append("status.getUserMentionEntities() = " + Arrays.toString(stat.getUserMentionEntities())); } catch (IOException ex) { textArea.append("IO Exception"); } catch (TwitterException tw) { textArea.append("Twitter Exception"); } }
From source file:wordgame.WordGame.java
public static void announce(String str) throws TwitterException { System.out.println(str);// ww w . j a v a2s . co m StatusUpdate rt = new StatusUpdate(str); WordGame.t.updateStatus(rt); }