List of usage examples for twitter4j Paging Paging
public Paging(long sinceId)
From source file:twitter.botframework.connector.TwitterBotframeworkConnector.java
public static void GetDirectMessage(Twitter twitter) throws ApiException, InterruptedException { //Twitter twitter = new TwitterFactory().getInstance(); try {//from w w w . ja v a 2 s . co m 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()); user_name = user_name.concat(message.getSenderScreenName()); user_message = message.getText(); //send a tweet //Status status = twitter.updateStatus("Hola " +user_name +" Estamos atendiendo tu peticion! #Fintechando #HaciendoElParo"); DirectLineToBot(user_name, user_message); SendDirectMessageAsResponse(twitter); } 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()); } catch (ApiException te) { te.printStackTrace(); System.out.println("Failed to get messages: " + te.getMessage()); } }
From source file:twittertimeline.MainFrame.java
private void refreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshActionPerformed // TODO add your handling code here: //We download timeline again. And values sets to 1. //Tweets are refreshed. So, we can clean our rt and fw lists too. try {/* w ww . j av a2 s. c om*/ pageCounter = 1; twCounter = 1; pg = new Paging(pageCounter); pageCounter++; status1 = twt.getHomeTimeline(pg); rtList = new ArrayList<Long>(); fwList = new ArrayList<Long>(); getTweets(); showTweets(); } catch (Exception e) { } }
From source file:twittertimeline.MainFrame.java
public void SetTwitter() throws TwitterException { //Keys//from w w w . j ava 2 s.c o m ConfigurationBuilder cf = new ConfigurationBuilder(); cf.setDebugEnabled(true).setOAuthConsumerKey("").setOAuthConsumerSecret("").setOAuthAccessToken("") .setOAuthAccessTokenSecret(""); //Create twitter object tw = new TwitterFactory(cf.build()); twt = tw.getInstance(); //Setting the photo of login user BufferedImage img = null; try { img = ImageIO.read(new URL(twt.showUser("username").getOriginalProfileImageURL())); photo.setIcon( new ImageIcon(img.getScaledInstance(photo.getWidth(), photo.getHeight(), img.SCALE_DEFAULT))); } catch (Exception e) { photo.setText("Photo Error"); } pg = new Paging(pageCounter); pageCounter++; //Get first page of timeline status1 = twt.getHomeTimeline(pg); rtList = new ArrayList<Long>(); fwList = new ArrayList<Long>(); getTweets(); showTweets(); }
From source file:twittertimeline.MainFrame.java
void getTweets() throws TwitterException { int start = pageCounter; pageCounter += 5;// w w w . j a va 2 s . c om for (int counter = start; counter <= pageCounter; counter++) { pg = new Paging(counter); status2 = twt.getHomeTimeline(pg); if (status2.isEmpty()) break; for (Status s : status2) { status1.add(s); } } }