List of usage examples for twitter4j.conf ConfigurationBuilder build
public Configuration build()
From source file:twitterNetwork.Follower.java
public void getDetails(String id) throws Exception { ConfigurationBuilder cb1 = new ConfigurationBuilder(); cb1.setOAuthConsumerKey(consumerKey1); cb1.setOAuthConsumerSecret(consumerSecret1); cb1.setOAuthAccessToken(twitterToken1); cb1.setOAuthAccessTokenSecret(twitterSecret1); ConfigurationBuilder cb2 = new ConfigurationBuilder(); cb2.setOAuthConsumerKey(consumerKey2); cb2.setOAuthConsumerSecret(consumerSecret2); cb2.setOAuthAccessToken(twitterToken2); cb2.setOAuthAccessTokenSecret(twitterSecret2); ConfigurationBuilder cb3 = new ConfigurationBuilder(); cb3.setOAuthConsumerKey(consumerKey3); cb3.setOAuthConsumerSecret(consumerSecret3); cb3.setOAuthAccessToken(twitterToken3); cb3.setOAuthAccessTokenSecret(twitterSecret3); Twitter twitter1 = new TwitterFactory(cb1.build()).getInstance(); Twitter twitter2 = new TwitterFactory(cb2.build()).getInstance(); Twitter twitter3 = new TwitterFactory(cb3.build()).getInstance(); ConfigurationBuilder cb4 = new ConfigurationBuilder(); cb4.setOAuthConsumerKey(consumerKey4); cb4.setOAuthConsumerSecret(consumerSecret4); cb4.setOAuthAccessToken(twitterToken4); cb4.setOAuthAccessTokenSecret(twitterSecret4); ConfigurationBuilder cb5 = new ConfigurationBuilder(); cb5.setOAuthConsumerKey(consumerKey5); cb5.setOAuthConsumerSecret(consumerSecret5); cb5.setOAuthAccessToken(twitterToken5); cb5.setOAuthAccessTokenSecret(twitterSecret5); ConfigurationBuilder cb6 = new ConfigurationBuilder(); cb6.setOAuthConsumerKey(consumerKey6); cb6.setOAuthConsumerSecret(consumerSecret6); cb6.setOAuthAccessToken(twitterToken6); cb6.setOAuthAccessTokenSecret(twitterSecret6); ConfigurationBuilder cb7 = new ConfigurationBuilder(); cb7.setOAuthConsumerKey(consumerKey7); cb7.setOAuthConsumerSecret(consumerSecret7); cb7.setOAuthAccessToken(twitterToken7); cb7.setOAuthAccessTokenSecret(twitterSecret7); ConfigurationBuilder cb8 = new ConfigurationBuilder(); cb8.setOAuthConsumerKey(consumerKey8); cb8.setOAuthConsumerSecret(consumerSecret8); cb8.setOAuthAccessToken(twitterToken8); cb8.setOAuthAccessTokenSecret(twitterSecret8); Twitter twitter4 = new TwitterFactory(cb4.build()).getInstance(); Twitter twitter5 = new TwitterFactory(cb5.build()).getInstance(); Twitter twitter6 = new TwitterFactory(cb6.build()).getInstance(); Twitter twitter7 = new TwitterFactory(cb7.build()).getInstance(); Twitter twitter8 = new TwitterFactory(cb8.build()).getInstance(); setTname(id);//from ww w . j a va 2s. com String twittername = this.tname; System.out.println(twittername); //User u=twitter.showUser(usr); //PrintStream out=new PrintStream(new FileOutputStream("F:\\Projects\\Twitter_Network\\out.txt")); int w1 = 1, w2 = 1, w3 = 1, w4 = 1, w5 = 1, w6 = 1, w7 = 1, w8 = 1; //long id=u.getId(); long lCursor = -1, nextCursor = -1; do { String twitterScreenName = twitter1.getScreenName(); IDs followersIDs = twitter1.getFollowersIDs(twitterScreenName, -1); lCursor = nextCursor; //out.println("###"+nextCursor); //label: if (w1 != 16) { try { followersIDs = twitter1.getFollowersIDs(twitterScreenName, lCursor); long[] ids = followersIDs.getIDs(); String usr = twittername; long[] fofIDs; User user = twitter1.showUser(usr); String userScreenName = user.getScreenName(); IDs followerIDsOfFollowers = twitter1.getFollowersIDs(user.getScreenName(), -1); long[] arrl = fofIDs = followerIDsOfFollowers.getIDs(); int n = arrl.length; int n2 = 0; while (n2 < n) { long subId = arrl[n2]; User user1 = twitter1.showUser(subId); if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) { this.ar.add(user1.getScreenName()); this.arpic.add(user1.getMiniProfileImageURL()); } ++n2; //TimeUnit.MINUTES.sleep(16); } } catch (Exception e) { e.printStackTrace(); } /*for(long k: followersIDs.getIDs()){ //User p=twitter.showUser(k); out.println(k); }*/ nextCursor = followersIDs.getNextCursor(); w1++; } else if (w2 != 16) { try { followersIDs = twitter2.getFollowersIDs(twitterScreenName, lCursor); long[] ids = followersIDs.getIDs(); String usr = twittername; long[] fofIDs; User user = twitter2.showUser(usr); String userScreenName = user.getScreenName(); IDs followerIDsOfFollowers = twitter2.getFollowersIDs(user.getScreenName(), -1); long[] arrl = fofIDs = followerIDsOfFollowers.getIDs(); int n = arrl.length; int n2 = 0; while (n2 < n) { long subId = arrl[n2]; User user1 = twitter2.showUser(subId); if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) { this.ar.add(user1.getScreenName()); this.arpic.add(user1.getMiniProfileImageURL()); } ++n2; //TimeUnit.MINUTES.sleep(16); } } catch (Exception e) { e.printStackTrace(); } /*for(long k: followersIDs.getIDs()){ //User p=twitter.showUser(k); out.println(k); }*/ nextCursor = followersIDs.getNextCursor(); w2++; } else if (w3 != 16) { //IDs followerIDs = twitter3.getFollowersIDs(twitterScreenName, -1); try { followersIDs = twitter3.getFollowersIDs(twitterScreenName, lCursor); long[] ids = followersIDs.getIDs(); String usr = twittername; long[] fofIDs; User user = twitter3.showUser(usr); String userScreenName = user.getScreenName(); IDs followerIDsOfFollowers = twitter3.getFollowersIDs(user.getScreenName(), -1); long[] arrl = fofIDs = followerIDsOfFollowers.getIDs(); int n = arrl.length; int n2 = 0; while (n2 < n) { long subId = arrl[n2]; User user1 = twitter3.showUser(subId); if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) { this.ar.add(user1.getScreenName()); this.arpic.add(user1.getMiniProfileImageURL()); } ++n2; //TimeUnit.MINUTES.sleep(16); } } catch (Exception e) { e.printStackTrace(); } /*for(long k: followersIDs.getIDs()){ //User p=twitter.showUser(k); out.println(k); }*/ nextCursor = followersIDs.getNextCursor(); w3++; } else if (w4 != 16) { //IDs followerIDs = twitter4.getFollowersIDs(twitterScreenName, -1); try { followersIDs = twitter4.getFollowersIDs(twitterScreenName, lCursor); long[] ids = followersIDs.getIDs(); String usr = twittername; long[] fofIDs; User user = twitter4.showUser(usr); String userScreenName = user.getScreenName(); IDs followerIDsOfFollowers = twitter4.getFollowersIDs(user.getScreenName(), -1); long[] arrl = fofIDs = followerIDsOfFollowers.getIDs(); int n = arrl.length; int n2 = 0; while (n2 < n) { long subId = arrl[n2]; User user1 = twitter4.showUser(subId); if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) { this.ar.add(user1.getScreenName()); this.arpic.add(user1.getMiniProfileImageURL()); } ++n2; //TimeUnit.MINUTES.sleep(16); } } catch (Exception e) { e.printStackTrace(); } /*for(long k: followersIDs.getIDs()){ //User p=twitter.showUser(k); out.println(k); }*/ nextCursor = followersIDs.getNextCursor(); w4++; } else if (w5 != 16) { //IDs followerIDs = twitter5.getFollowersIDs(twitterScreenName, -1); try { followersIDs = twitter5.getFollowersIDs(twitterScreenName, lCursor); long[] ids = followersIDs.getIDs(); String usr = twittername; long[] fofIDs; User user = twitter5.showUser(usr); String userScreenName = user.getScreenName(); IDs followerIDsOfFollowers = twitter5.getFollowersIDs(user.getScreenName(), -1); long[] arrl = fofIDs = followerIDsOfFollowers.getIDs(); int n = arrl.length; int n2 = 0; while (n2 < n) { long subId = arrl[n2]; User user1 = twitter5.showUser(subId); if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) { this.ar.add(user1.getScreenName()); this.arpic.add(user1.getMiniProfileImageURL()); } ++n2; //TimeUnit.MINUTES.sleep(16); } } catch (Exception e) { e.printStackTrace(); } /*for(long k: followersIDs.getIDs()){ //User p=twitter.showUser(k); out.println(k); }*/ nextCursor = followersIDs.getNextCursor(); w5++; } else if (w6 != 16) { //IDs followerIDs = twitter6.getFollowersIDs(twitterScreenName, -1); try { followersIDs = twitter6.getFollowersIDs(twitterScreenName, lCursor); long[] ids = followersIDs.getIDs(); String usr = twittername; long[] fofIDs; User user = twitter6.showUser(usr); String userScreenName = user.getScreenName(); IDs followerIDsOfFollowers = twitter6.getFollowersIDs(user.getScreenName(), -1); long[] arrl = fofIDs = followerIDsOfFollowers.getIDs(); int n = arrl.length; int n2 = 0; while (n2 < n) { long subId = arrl[n2]; User user1 = twitter6.showUser(subId); if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) { this.ar.add(user1.getScreenName()); this.arpic.add(user1.getMiniProfileImageURL()); } ++n2; //TimeUnit.MINUTES.sleep(16); } } catch (Exception e) { e.printStackTrace(); } /*for(long k: followersIDs.getIDs()){ //User p=twitter.showUser(k); out.println(k); }*/ nextCursor = followersIDs.getNextCursor(); w6++; } else if (w7 != 16) { //IDs followerIDs = twitter7.getFollowersIDs(twitterScreenName, -1); try { followersIDs = twitter7.getFollowersIDs(twitterScreenName, lCursor); long[] ids = followersIDs.getIDs(); String usr = twittername; long[] fofIDs; User user = twitter7.showUser(usr); String userScreenName = user.getScreenName(); IDs followerIDsOfFollowers = twitter7.getFollowersIDs(user.getScreenName(), -1); long[] arrl = fofIDs = followerIDsOfFollowers.getIDs(); int n = arrl.length; int n2 = 0; while (n2 < n) { long subId = arrl[n2]; User user1 = twitter7.showUser(subId); if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) { this.ar.add(user1.getScreenName()); this.arpic.add(user1.getMiniProfileImageURL()); } ++n2; //TimeUnit.MINUTES.sleep(16); } } catch (Exception e) { e.printStackTrace(); } /*for(long k: followersIDs.getIDs()){ //User p=twitter.showUser(k); out.println(k); }*/ nextCursor = followersIDs.getNextCursor(); w7++; } else if (w8 != 16) { //IDs followerIDs = twitter8.getFollowersIDs(twitterScreenName, -1); try { followersIDs = twitter8.getFollowersIDs(twitterScreenName, lCursor); long[] ids = followersIDs.getIDs(); String usr = twittername; long[] fofIDs; User user = twitter8.showUser(usr); String userScreenName = user.getScreenName(); IDs followerIDsOfFollowers = twitter8.getFollowersIDs(user.getScreenName(), -1); long[] arrl = fofIDs = followerIDsOfFollowers.getIDs(); int n = arrl.length; int n2 = 0; while (n2 < n) { long subId = arrl[n2]; User user1 = twitter8.showUser(subId); if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) { this.ar.add(user1.getScreenName()); this.arpic.add(user1.getMiniProfileImageURL()); } ++n2; //TimeUnit.MINUTES.sleep(16); } } catch (Exception e) { e.printStackTrace(); } /*for(long k: followersIDs.getIDs()){ //User p=twitter.showUser(k); out.println(k); }*/ nextCursor = followersIDs.getNextCursor(); w8++; /*if(twitter8.getRateLimitStatus()!=null){ if (twitter8.getRateLimitStatus().get("/users/lookup") != null){ // break label; } }*/ } else { try { TimeUnit.MINUTES.sleep(16); } catch (InterruptedException e) { e.printStackTrace(); } w1 = 1; w2 = 1; w3 = 1; w4 = 1; w5 = 1; w6 = 1; w7 = 1; w8 = 1; } } while (nextCursor != 0); //out.flush(); //out.close(); }
From source file:twitterNetwork.twitteridextraction.java
public static void main(String args[]) throws TwitterException { ConfigurationBuilder cb1 = new ConfigurationBuilder(); cb1.setOAuthConsumerKey(consumerKey2); cb1.setOAuthConsumerSecret(consumerSecret2); cb1.setOAuthAccessToken(twitterToken2); cb1.setOAuthAccessTokenSecret(twitterSecret2); Twitter twitter = new TwitterFactory(cb1.build()).getInstance(); User user = twitter.showUser(5108161); System.out.println(user.getName()); System.out.println("<h3>Displaying user id of user " + user.getScreenName() + "</h3><br/>"); System.out.println(user.getId()); }
From source file:twitterNetwork.extractUser.java
/*****token*/ public void dataextraction(ArrayList userName, int k, int l) { /*****///from ww w. j av a 2 s . com ConfigurationBuilder cb1 = new ConfigurationBuilder(); cb1.setOAuthConsumerKey(consumerKey1); cb1.setOAuthConsumerSecret(consumerSecret1); cb1.setOAuthAccessToken(twitterToken1); cb1.setOAuthAccessTokenSecret(twitterSecret1); ConfigurationBuilder cb2 = new ConfigurationBuilder(); cb2.setOAuthConsumerKey(consumerKey2); cb2.setOAuthConsumerSecret(consumerSecret2); cb2.setOAuthAccessToken(twitterToken2); cb2.setOAuthAccessTokenSecret(twitterSecret2); ConfigurationBuilder cb3 = new ConfigurationBuilder(); cb3.setOAuthConsumerKey(consumerKey3); cb3.setOAuthConsumerSecret(consumerSecret3); cb3.setOAuthAccessToken(twitterToken3); cb3.setOAuthAccessTokenSecret(twitterSecret3); Twitter twitter1 = new TwitterFactory(cb1.build()).getInstance(); Twitter twitter2 = new TwitterFactory(cb2.build()).getInstance(); Twitter twitter3 = new TwitterFactory(cb3.build()).getInstance(); ConfigurationBuilder cb4 = new ConfigurationBuilder(); cb4.setOAuthConsumerKey(consumerKey4); cb4.setOAuthConsumerSecret(consumerSecret4); cb4.setOAuthAccessToken(twitterToken4); cb4.setOAuthAccessTokenSecret(twitterSecret4); ConfigurationBuilder cb5 = new ConfigurationBuilder(); cb5.setOAuthConsumerKey(consumerKey5); cb5.setOAuthConsumerSecret(consumerSecret5); cb5.setOAuthAccessToken(twitterToken5); cb5.setOAuthAccessTokenSecret(twitterSecret5); ConfigurationBuilder cb6 = new ConfigurationBuilder(); cb6.setOAuthConsumerKey(consumerKey6); cb6.setOAuthConsumerSecret(consumerSecret6); cb6.setOAuthAccessToken(twitterToken6); cb6.setOAuthAccessTokenSecret(twitterSecret6); ConfigurationBuilder cb7 = new ConfigurationBuilder(); cb7.setOAuthConsumerKey(consumerKey7); cb7.setOAuthConsumerSecret(consumerSecret7); cb7.setOAuthAccessToken(twitterToken7); cb7.setOAuthAccessTokenSecret(twitterSecret7); ConfigurationBuilder cb8 = new ConfigurationBuilder(); cb8.setOAuthConsumerKey(consumerKey8); cb8.setOAuthConsumerSecret(consumerSecret8); cb8.setOAuthAccessToken(twitterToken8); cb8.setOAuthAccessTokenSecret(twitterSecret8); Twitter twitter4 = new TwitterFactory(cb4.build()).getInstance(); Twitter twitter5 = new TwitterFactory(cb5.build()).getInstance(); Twitter twitter6 = new TwitterFactory(cb6.build()).getInstance(); Twitter twitter7 = new TwitterFactory(cb7.build()).getInstance(); Twitter twitter8 = new TwitterFactory(cb8.build()).getInstance(); System.out.println("k" + k + "l" + l); int j = k; Follower obj = new Follower(); User user1 = null; while (j < userName.size()) { try { // System.out.println(userName.get(j)); int name = Integer.parseInt(userName.get(j).toString()); if (l == 1) { user1 = twitter7.showUser(name); } else if (l == 2) { user1 = twitter2.showUser(name); } else if (l == 3) { user1 = twitter3.showUser(name); } else if (l == 4) { user1 = twitter4.showUser(name); } else if (l == 5) { user1 = twitter5.showUser(name); } else if (l == 6) { user1 = twitter6.showUser(name); } else if (l == 7) { user1 = twitter1.showUser(name); } else if (l == 8) { user1 = twitter8.showUser(name); } else { l = 1; dataextraction(userName, j, l); } //System.out.println(userName.get(j)+"---"+j); if (user1.getRateLimitStatus().getRemaining() > 2) { System.out.println(userName.get(j) + "," + user1.getScreenName()); } else { System.out.println("rate2"); //System.out.println(l+1+"---"+j); int m = l + 1; if (m == 9) { m = 1; } dataextraction(userName, j, m); } } catch (Exception e) { System.out.println(e.getMessage()); } j++; } }
From source file:twitterplugin.TwitterSender.java
License:Open Source License
public void send(final Window parentWindow, final Program program, final TwitterSettings settings) { TwitterDialog dialog = new TwitterDialog(parentWindow, program, settings.getFormat()); dialog.setLocationRelativeTo(parentWindow); dialog.setVisible(true);//from w ww. j a va 2 s . c o m if (dialog.wasOkPressed()) { if (settings.getAccessToken() == null) { final TwitterLoginDialog login = new TwitterLoginDialog(parentWindow, settings); if (!(login.askLogin() == JOptionPane.OK_OPTION)) { return; } } ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(settings.getConsumerKey()) .setOAuthConsumerSecret(settings.getConsumerSecret()); TwitterFactory factory = new TwitterFactory(cb.build()); AccessToken accessToken = settings.getAccessToken(); Twitter twitter = factory.getInstance(accessToken); try { twitter.updateStatus(dialog.getMessage()); DontShowAgainMessageBox.dontShowAgainMessageBox(TwitterPlugin.getInstance(), "tweetSent", parentWindow, mLocalizer.msg("tweetSend", "The tweet was sent.")); } catch (TwitterException e) { e.printStackTrace(); ErrorHandler.handle(mLocalizer.msg("error", "Could not send tweet..."), e); } } }
From source file:twittersentimentanalysis.TwitterSentimentAnalysis.java
public static void main(String[] args) { try {/*from w w w. java 2s .com*/ fh = new FileHandler("C:/Mitali/Logs/MyLogFile.log"); logger.addHandler(fh); SimpleFormatter formatter = new SimpleFormatter(); fh.setFormatter(formatter); logger.info("Twitter Sentiment Analysis Started!!!"); ConfigurationBuilder cb; Twitter twitter; cb = getAuthentication(); twitter = new TwitterFactory(cb.build()).getInstance(); ArrayList<Tweet> listOfTweets = getAllTweets(twitter); System.out.println("Size : " + listOfTweets.size()); int result = insertIntoDatabase(listOfTweets); logger.info("Number of tweets added = " + result); } catch (IOException ex) { Logger.getLogger(TwitterSentimentAnalysis.class.getName()).log(Level.SEVERE, null, ex); logger.info(ex.getMessage()); } catch (SecurityException ex) { Logger.getLogger(TwitterSentimentAnalysis.class.getName()).log(Level.SEVERE, null, ex); logger.info(ex.getMessage()); } }
From source file:TwitterStats.Facade.Twitter.java
public Twitter() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey("4bUGil5YTghhAZj05wJZX0wjB"); builder.setOAuthAccessToken("330584281-bFRvETvWXnH7fb9acRMIIagP1oGQeMK0mv4RiIUB"); builder.setOAuthConsumerSecret("nZPD0wtVuQRmqSdyEnGN4d8TRv63BPlUvkVOAZSZ2O8DfDGwGX"); builder.setOAuthAccessTokenSecret("FGSC23QvIqBYRKleno9OQI3eBo8J54hZ5btpAf1jR2bYy"); twitter4j.conf.Configuration configuration = builder.build(); twitter = (new TwitterFactory(configuration)).getInstance(); }
From source file:twittertestingagain.TwitterTesting.java
/** * @param args the command line arguments * @throws twitter4j.TwitterException/* w w w .j a v a 2 s .c om*/ * @throws java.io.IOException */ public static void main(String[] args) throws TwitterException, IOException { /* ---------------------------Setting up twitter account authentication-------------------------------*/ ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("YjICBJeNlnxAf3tFw7awLaCzS") .setOAuthConsumerSecret("8IfPzkr4opePnhCLLloKMP6X44IeNav0fLDrmtBrPbaHoxd1nO") .setOAuthAccessToken("4146680697-oOEPVezvvZ82vB7iP9HSbkoTG9ze9gH69XLrSCP") .setOAuthAccessTokenSecret("HZjsaabmVjeSkSX6vvVFdT3GWZek8xJ9RKfwaR57RDyEG"); /* ---------------------------------File Writing Variables------------------------------------------------*/ File outfile = new File("output.txt"); FileWriter fwriter = new FileWriter(outfile); try (PrintWriter pWriter = new PrintWriter(fwriter)) { /*----------------------------------Search Parameters-------------------------------------*/ String search = "chinese food"; String lang = "en"; /*------------------------End Search Parameters----------------------------------------*/ int numTweets = 0; long maxID = -1; TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); try { Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus("search"); //System.out.println(rateLimitStatus); RateLimitStatus searchTweetsRateLimit = rateLimitStatus.get("/search/tweets"); /*System.out.printf("You have %d calls remaining out of %d, Limit resets in %d seconds\n", searchTweetsRateLimit.getRemaining(), searchTweetsRateLimit.getLimit(), searchTweetsRateLimit.getSecondsUntilReset()); */ for (int queryNumber = 0; queryNumber < maxQueries; queryNumber++) { System.out.printf("\n\n!!! Starting loop %d\n\n", queryNumber); pWriter.println("\n\n!!! Starting iteration #" + queryNumber + "\n\n"); if (searchTweetsRateLimit.getRemaining() == 0) { System.out.printf("!!! Sleeping for %d seconds due to rate limits\n", searchTweetsRateLimit.getSecondsUntilReset()); Thread.sleep((searchTweetsRateLimit.getSecondsUntilReset() + 2) * 1000l); } //here is where we can send an object to the query Query query = new Query(search); query.setCount(tweetsPerQuery); query.resultType(Query.ResultType.recent); query.setLang(lang); if (maxID != -1) { query.setMaxId(maxID - 1); } QueryResult result = twitter.search(query); if (result.getTweets().size() == 0) { break; } for (Status s : result.getTweets()) { numTweets++; if (maxID == -1 || s.getId() < maxID) { maxID = s.getId(); } System.out.printf("On %s, @%-20s said: %s\n", s.getCreatedAt().toString(), s.getUser().getScreenName(), cleanText(s.getText())); pWriter.println("On " + s.getCreatedAt().toString() + " @" + s.getUser().getScreenName() + " " + cleanText(s.getText())); } searchTweetsRateLimit = result.getRateLimitStatus(); } } catch (Exception e) { System.out.println("Broken"); e.printStackTrace(); } System.out.printf("\n\nA total of %d tweets retrieved\n", numTweets); pWriter.println("\n\nA total of " + numTweets + " tweets retrieved\n\n"); pWriter.close(); /*while (result.hasNext()){ numTweets += result.getCount(); System.out.println(numTweets); for (Status status : result.getTweets()) { System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); } result.nextQuery(); } /* QueryForm qf = new QueryForm(); qf.show(); */ } }
From source file:twittertimeline.MainFrame.java
public void SetTwitter() throws TwitterException { //Keys//from ww w .j a va 2 s .c om 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:twittertweetscollection.TwitterTweetsCollection.java
public List<Status> execute() throws TwitterException { final List<Status> statuses = new ArrayList(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("I7WYWBE6eSNKdV4FYSyiuP0uk") .setOAuthConsumerSecret("oft7Y6WcUCvxovPU5modCZ3BOlHH2z9Px73UkFMILN4ltBhOni") .setOAuthAccessToken("3524247253-o7zXFn3r8PwPb4IUTYqHRQzVabTzfoFn9Ck7FzW") .setOAuthAccessTokenSecret("V7zkLiJmF0vsdX8rUdkXo3q1ha452vKqVtB5OoCuQWAgR"); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener listener = new StatusListener() { public void onStatus(Status status) { statuses.add(status);//from w w w . j ava 2s. co m System.out.println(statuses.size() + ":" + status.getText()); if (statuses.size() > 100) { synchronized (lock) { lock.notify(); } System.out.println("unlocked"); } } public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } public void onException(Exception ex) { ex.printStackTrace(); } @Override public void onStallWarning(StallWarning sw) { System.out.println(sw.getMessage()); } }; //FilterQuery fq = new FilterQuery(); //String keywords[] = { "SuperBowlSunday"}; //fq.track(keywords); twitterStream.addListener(listener); twitterStream.sample(); //twitterStream.filter(fq); try { synchronized (lock) { lock.wait(); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("returning statuses"); twitterStream.shutdown(); return statuses; }
From source file:twitter_app_p1.Twitter_app_p1.java
public static void initialize_stuff() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("T9Gl1DWeRjeBazUInktTNtEtD") .setOAuthConsumerSecret("3NXrL1qGpF3WPVyJQ7ytInlhNjIsMgT6s7bJOIDhD1uotzZ958") .setOAuthAccessToken("2428771880-4e3LHhOzmiYx4lChlAEYtJ6sB2oetARYbXcqfyU") .setOAuthAccessTokenSecret("7HLOf3dafjJEGoioWOMHfgiNrhBDb66YJZgSzrDkTNA9x") .setJSONStoreEnabled(true);/* w w w. j a v a2 s . c o m*/ TwitterStreamFactory twitterStreamFact = new TwitterStreamFactory(cb.build()); twitterStream = twitterStreamFact.getInstance(); }