List of usage examples for twitter4j.conf ConfigurationBuilder setDebugEnabled
public ConfigurationBuilder setDebugEnabled(boolean debugEnabled)
From source file:twitfeedbot.BotherSomeoneServlet.java
License:Open Source License
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { Twitter twit;/*w w w . j av a 2 s . c o m*/ StringBuilder builder = new StringBuilder(); User victim = null; long cursor = -1; long[] friendIDs, victimIDs; Random r = new Random(); resp.setContentType("text/html"); resp.getWriter().println("<html>"); resp.getWriter().println("<body>"); try { ConfigurationBuilder twitterConfigBuilder = new ConfigurationBuilder(); twitterConfigBuilder.setDebugEnabled(false); System.setProperty("WORDNIK_API_KEY", WORDNIK_KEY); twitterConfigBuilder.setOAuthConsumerKey(CONSUMER_KEY); twitterConfigBuilder.setOAuthConsumerSecret(CONSUMER_SECRET); twitterConfigBuilder.setOAuthAccessToken(ACCESS_TOKEN); twitterConfigBuilder.setOAuthAccessTokenSecret(ACCESS_SECRET); twit = new TwitterFactory(twitterConfigBuilder.build()).getInstance(); Trends t = twit.getPlaceTrends(1); //global trends friendIDs = twit.getFollowersIDs(twit.getId(), cursor).getIDs(); if (friendIDs.length == 0) resp.getWriter().println("Cannot find any followers to bother"); else { victimIDs = twit.getFollowersIDs(friendIDs[r.nextInt(friendIDs.length)], cursor).getIDs(); if (victimIDs.length == 0) resp.getWriter().println("Cannot find any followers to bother"); else { victim = twit.showUser(victimIDs[r.nextInt(victimIDs.length)]); builder.append("@" + victim.getScreenName()).append(" "); //Append Wordnik example sentence builder.append(WordApi.topExample(WordsApi.randomWord().getWord()).getText()); if (builder.length() > 140) //Tweets are maximum 140 characters { if (builder.lastIndexOf(";", 110) > 0) builder.setLength(builder.lastIndexOf(";", 110)); else if (builder.lastIndexOf(":", 110) > 0) builder.setLength(builder.lastIndexOf(":", 110)); else if (builder.lastIndexOf(",", 110) > 0) builder.setLength(builder.lastIndexOf(",", 110)); else builder.setLength(110); } builder.append(" " + t.getTrends()[r.nextInt(t.getTrends().length)].getName()); if (builder.length() > 140) builder.setLength(140); //Tweets are limited to 140 characters twit.updateStatus(builder.toString()); resp.getWriter().println("Tweet posted: " + builder.toString() + "<br>"); } } } catch (FileNotFoundException e) { e.printStackTrace(System.err); resp.getWriter().println("Input file(s) not found<br>"); resp.getWriter().println("<pre>"); e.printStackTrace(resp.getWriter()); resp.getWriter().println("</pre>"); } catch (TwitterException e) { resp.getWriter().println("Problem with Twitter <br>"); resp.getWriter().println("<pre>"); e.printStackTrace(resp.getWriter()); resp.getWriter().println("</pre>"); } catch (KnickerException e) { e.printStackTrace(System.err); resp.getWriter().println("Problem with Wordnik <br>"); resp.getWriter().println("<pre>"); e.printStackTrace(resp.getWriter()); resp.getWriter().println("</pre>"); } catch (Exception e) { e.printStackTrace(System.err); resp.getWriter().println("<pre>"); e.printStackTrace(resp.getWriter()); resp.getWriter().println("</pre>"); } }
From source file:twitfeedbot.RespondServlet.java
License:Open Source License
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { ResponseList<Status> mentions; Twitter twit;/*from w w w . j a v a2 s. c o m*/ StringBuilder builder = new StringBuilder(); long lastPostId = 0; DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Entity lastPostIdEntity; resp.setContentType("text/html"); resp.getWriter().println("<html>"); resp.getWriter().println("<body>"); try { ConfigurationBuilder twitterConfigBuilder = new ConfigurationBuilder(); twitterConfigBuilder.setDebugEnabled(false); System.setProperty("WORDNIK_API_KEY", WORDNIK_KEY); twitterConfigBuilder.setOAuthConsumerKey(CONSUMER_KEY); twitterConfigBuilder.setOAuthConsumerSecret(CONSUMER_SECRET); twitterConfigBuilder.setOAuthAccessToken(ACCESS_TOKEN); twitterConfigBuilder.setOAuthAccessTokenSecret(ACCESS_SECRET); twit = new TwitterFactory(twitterConfigBuilder.build()).getInstance(); mentions = twit.getMentionsTimeline(); lastPostIdEntity = datastore.get(KeyFactory.createKey("lastPostIDEntity", "ID")); lastPostId = Long.parseLong(lastPostIdEntity.getProperty("lastPostID").toString()); if (mentions.size() == 0 || mentions.get(0).getId() == lastPostId) resp.getWriter().println("No mentions so far...<br>"); else { resp.getWriter().println("Responding to mentions...<br>"); for (Status mention : mentions) { builder.setLength(0); // Clear the String Builder if (lastPostId < mention.getId()) { //Figure out how to like a reply with certain words (best fuck etc) if (mention.getUser().getId() == twit.getId()) ;//don't respond to myself else if (mention.isRetweeted()) ; //don't respond to retweet else if (mention.getText().toLowerCase().contains("bye")) // Say goodbye { builder.setLength(0); // Clear the String Builder builder.append("@").append(mention.getUser().getScreenName()).append(" Ok. Bye"); } else { builder.setLength(0); // Clear the String Builder builder.append("@").append(mention.getUser().getScreenName()); builder.append(" "); //Append Wordnik example sentence builder.append(WordApi.topExample(WordsApi.randomWord().getWord()).getText()); if (builder.length() > 140) { if (builder.lastIndexOf(";", 110) > 0) builder.setLength(builder.lastIndexOf(";", 110)); else if (builder.lastIndexOf(":", 110) > 0) builder.setLength(builder.lastIndexOf(":", 110)); else if (builder.lastIndexOf(",", 110) > 0) builder.setLength(builder.lastIndexOf(",", 110)); else builder.setLength(110); } } twit.updateStatus(builder.toString()); resp.getWriter().println("Reply posted: " + builder.toString() + "<br>"); builder.delete(0, builder.length()); //Clear the builder } } //Save last post ID lastPostIdEntity.setProperty("lastPostID", (Long.toString(mentions.get(0).getId()))); datastore.put(lastPostIdEntity); } } catch (FileNotFoundException e) { e.printStackTrace(System.err); resp.getWriter().println("Input file(s) not found<br>"); resp.getWriter().println("<pre>"); e.printStackTrace(resp.getWriter()); resp.getWriter().println("</pre>"); } catch (EntityNotFoundException e) { resp.getWriter().println("lastPostID not found. Creating...<br>"); lastPostIdEntity = new Entity("lastPostIDEntity", "ID"); //lastPostIdEntity.setProperty("lastPostID", 0); lastPostIdEntity.setProperty("lastPostID", "883352596160946176"); datastore.put(lastPostIdEntity); } catch (TwitterException e) { resp.getWriter().println("Problem with Twitter <br>"); resp.getWriter().println("<pre>"); e.printStackTrace(resp.getWriter()); resp.getWriter().println("</pre>"); } catch (KnickerException e) { e.printStackTrace(System.err); resp.getWriter().println("Problem with Wordnik <br>"); resp.getWriter().println("<pre>"); e.printStackTrace(resp.getWriter()); resp.getWriter().println("</pre>"); } catch (Exception e) { e.printStackTrace(System.err); resp.getWriter().println("<pre>"); e.printStackTrace(resp.getWriter()); resp.getWriter().println("</pre>"); } }
From source file:twitfeedbot.UpdateStatusServlet.java
License:Open Source License
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { StringBuilder builder = new StringBuilder(140); GetFeed feed = new GetFeed(feedsFile); Random r = new Random(); resp.setContentType("text/plain; charset=UTF-8"); try {// ww w .j ava 2s .c o m resp.getWriter().println("Updating status..."); ConfigurationBuilder twitterConfigBuilder = new ConfigurationBuilder(); twitterConfigBuilder.setDebugEnabled(false); System.setProperty("WORDNIK_API_KEY", WORDNIK_KEY); twitterConfigBuilder.setOAuthConsumerKey(CONSUMER_KEY); twitterConfigBuilder.setOAuthConsumerSecret(CONSUMER_SECRET); twitterConfigBuilder.setOAuthAccessToken(ACCESS_TOKEN); twitterConfigBuilder.setOAuthAccessTokenSecret(ACCESS_SECRET); twit = new TwitterFactory(twitterConfigBuilder.build()).getInstance(); //Append feed title try { builder.append(feed.title()).append(separator[(r.nextInt(separator.length))]); } catch (FeedException e) { resp.getWriter().println("Problem with RSS Feed <br> <pre>"); e.printStackTrace(resp.getWriter()); } //Append Wordnik example sentence builder.append(WordApi.topExample(WordsApi.randomWord().getWord()).getText()); if (builder.length() > 140) //Tweets are maximum 140 characters { if (builder.lastIndexOf(";", 110) > 0) builder.setLength(builder.lastIndexOf(";", 110)); else if (builder.lastIndexOf(":", 110) > 0) builder.setLength(builder.lastIndexOf(":", 110)); else if (builder.lastIndexOf(",", 110) > 0) builder.setLength(builder.lastIndexOf(",", 110)); else builder.setLength(110); } //Add a global trend builder.append( " " + twit.getPlaceTrends(1).getTrends()[r.nextInt(twit.getPlaceTrends(1).getTrends().length)] .getName()); // Make up a trend by combining two words builder.append(" #" + WordsApi.randomWord().getWord() + WordsApi.randomWord().getWord()); if (builder.length() > 140) builder.setLength(140); //Tweets are limited to 140 characters twit.updateStatus(builder.toString()); resp.getWriter().println("Tweet posted: " + builder.toString()); } catch (FileNotFoundException e) { e.printStackTrace(System.err); resp.getWriter().println("Input file(s) not found<br>"); resp.getWriter().println("<pre>"); e.printStackTrace(resp.getWriter()); resp.getWriter().println("</pre>"); } catch (TwitterException e) { resp.getWriter().println("Problem with Twitter <br>"); resp.getWriter().println("<pre>"); e.printStackTrace(resp.getWriter()); resp.getWriter().println("</pre>"); } catch (KnickerException e) { e.printStackTrace(System.err); resp.getWriter().println("Problem with Wordnik <br>"); resp.getWriter().println("<pre>"); e.printStackTrace(resp.getWriter()); resp.getWriter().println("</pre>"); } catch (Exception e) { e.printStackTrace(System.err); resp.getWriter().println("<pre>"); e.printStackTrace(resp.getWriter()); resp.getWriter().println("</pre>"); } }
From source file:Twitter.ajouterTweet.java
public String tweeter(String ch) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("JFpW0Gry4Wwst4jRT8ViuFcHz") .setOAuthConsumerSecret("dre4sGP8yjqRil59yCfHMWzgGzvM47AbddudsNaLaTWtFSdN8u") .setOAuthAccessToken("4174408527-H22us84yvMouxO9PgHKxfSswamhzreT3VOeeMYS") .setOAuthAccessTokenSecret("u5vlzN32AUv6UPLiblqQzs8vsnasMp0oZpiEaeRfVXRdH"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter4j.Twitter tw = tf.getInstance(); Status stat;/*from w w w .j ava2s. c o m*/ try { stat = tw.updateStatus(ch); return "Tweet ajout"; //System.out.println("twitter updated"); } catch (TwitterException ex) { ex.printStackTrace(); return "Tweet non ajout"; } }
From source file:Twitter.FilterStream.java
License:Apache License
public static void main(String[] args) throws TwitterException { System.getProperties().put("http.proxyHost", "127.0.0.1"); System.getProperties().put("http.proxyPort", "8580"); /* if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.PrintFilterStream [follow(comma separated numerical user ids)] [track(comma separated filter terms)]"); System.exit(-1);/* w w w. j a v a 2 s.c o m*/ }*/ final FilterStream fs = new FilterStream(); try { fs.LinkMongodb(); } catch (Exception e) { e.printStackTrace(); } StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); String str = DataObjectFactory.getRawJSON(status); try { //JSONObject nnstr = new JSONObject(newstr); DBObject dbObject = (DBObject) JSON.parse(str); fs.collection.insert(dbObject); //System.out.println(dbObject); fs.count++; if (fs.count > 900000000) { fs.mongo.close(); System.exit(0); } } catch (Exception e) { e.printStackTrace(); } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { System.out.println("Got stall warning:" + warning); } @Override public void onException(Exception ex) { ex.printStackTrace(); } }; ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("7ZVgfKiOvBDcDFpytRWSA") .setOAuthConsumerSecret("JmeJVeym78arzmGthrDUshQyhkq6nWA9tWLUKxc") .setOAuthAccessToken("321341780-Zy7LptVYBZBVvAeQ5GFJ4aKFw8sdqhWBnvA3pDuO") .setOAuthAccessTokenSecret("foi8FnQCeN0J5cdwad05Q6d7dbytFayQn1ZOvmhF6Qc"); cb.setJSONStoreEnabled(true); TwitterStreamFactory tf = new TwitterStreamFactory(cb.build()); TwitterStream twitterStream = tf.getInstance(); twitterStream.addListener(listener); ArrayList<Long> follow = new ArrayList<Long>(); ArrayList<String> track = new ArrayList<String>(); //String[] keywords = {"RT @justinbieber"}; String[] keywords = { "27260086" }; // user_id(justinbieber) for (String arg : keywords) { if (isNumericalArgument(arg)) { for (String id : arg.split(",")) { follow.add(Long.parseLong(id)); } } else { track.addAll(Arrays.asList(arg.split(","))); } } long[] followArray = new long[follow.size()]; for (int i = 0; i < follow.size(); i++) { followArray[i] = follow.get(i); } String[] trackArray = track.toArray(new String[track.size()]); // filter() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously. //twitterStream.filter(new FilterQuery(0, followArray, trackArray)); twitterStream.filter(new FilterQuery(followArray)); }
From source file:twitter.login.java
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed try {/*from w ww . java 2 s. c om*/ //Source Code untuk Login ke situs Twitter dengan memakai //ConsumerKey,ConsumerSecret,AccessToken,dan AccessSecret //datFo Data=new datFo(txtConsumerKey.getText(),arrayToString(txtConsumerSecret.getPassword()),txtAccessToken.getText(),arrayToString(txtAccessSecret.getPassword())); datFo Data = new datFo(); Data.setConsumerKey(txtConsumerKey.getText()); Data.setConsumerSecret(arrayToString(txtConsumerSecret.getPassword())); Data.setAccessKey(txtAccessToken.getText()); Data.setAccessSecret(arrayToString(txtAccessSecret.getPassword())); ConfigurationBuilder cf = new ConfigurationBuilder(); cf.setDebugEnabled(true).setOAuthConsumerKey(Data.getConsumerKey()) .setOAuthConsumerSecret(Data.getConsumerSecret()).setOAuthAccessToken(Data.getAccessKey()) .setOAuthAccessTokenSecret(Data.getAccessSecret()); TwitterFactory tf = new TwitterFactory(cf.build()); twitter4j.Twitter tw = tf.getInstance(); Home home = new Home(tw); home.setVisible(true); home.setAlwaysOnTop(true); this.setVisible(false); this.dispose(); } catch (TwitterException ex) { Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(this, "diCheck lagi bro Key nya\n Atau Check Koneksi Bro", "Error", JOptionPane.OK_OPTION); } }
From source file:twitter.metrics.TwitterMetrics.java
/** * @param args the command line arguments *//*from w w w . j a va2 s.c o m*/ public static void main(String[] args) { try { /*Parte que guarda en un archivo*/ // Se crea el libro HSSFWorkbook libro = new HSSFWorkbook(); // Se crea una hoja dentro del libro HSSFSheet hoja = libro.createSheet(); // Se crea una fila dentro de la hoja HSSFRow fila = hoja.createRow(0); // Se crea una celda dentro de la fila HSSFCell celda = fila.createCell(1); // Se crea el contenido de la celda y se mete en ella. HSSFRichTextString texto = new HSSFRichTextString("Metricas de Twitter"); celda.setCellValue(texto); /************************************/ /*Conexion con Mongo DB*/ MongoClient mongoClient = new MongoClient("localhost", 27017); DB db = mongoClient.getDB("JavaMongoTwitter"); DBCollection datos = db.getCollection("Datos"); /***********************/ ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); cb.setOAuthConsumerKey("TobUISZXWUhDda04ZBtFGQ"); cb.setOAuthConsumerSecret("7xurVN3iP6VDcBfKdFJxVuNsJjExERFYNmQIDgtg"); cb.setOAuthAccessToken("849956971-GJBiORhLIuWK4i3MJ2YCd4vidh65N1GzPIb6duXk"); cb.setOAuthAccessTokenSecret("4MJgPS9grxVuKbczrPCdSjNnumhcWs7t7OLy2F4kkpOdu"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); User u = twitter.showUser("Pringles"); System.out.println("Nombre: " + u.getName()); System.out.println("Seguidores: " + u.getFollowersCount()); System.out.println("Favoritos: " + u.getFavouritesCount()); System.out.println("Seguidos: " + u.getFriendsCount()); System.out.println("Ubicacion: " + u.getLocation()); System.out.println("Descripcin: " + u.getDescription()); System.out.println(""); fila = hoja.createRow(1); celda = fila.createCell(0); celda.setCellValue(new HSSFRichTextString("Nombre:")); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(u.getName())); fila = hoja.createRow(2); celda = fila.createCell(0); celda.setCellValue(new HSSFRichTextString("Seguidores:")); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(u.getFollowersCount() + "")); fila = hoja.createRow(3); celda = fila.createCell(0); celda.setCellValue(new HSSFRichTextString("Favoritos:")); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(u.getFavouritesCount() + "")); fila = hoja.createRow(4); celda = fila.createCell(0); celda.setCellValue(new HSSFRichTextString("Seguidos:")); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(u.getFriendsCount() + "")); fila = hoja.createRow(5); celda = fila.createCell(0); celda.setCellValue(new HSSFRichTextString("Ubicacin:")); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(u.getLocation() + "")); fila = hoja.createRow(6); celda = fila.createCell(0); celda.setCellValue(new HSSFRichTextString("Descripcin:")); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(u.getDescription() + "")); fila = hoja.createRow(7); celda = fila.createCell(3); celda.setCellValue(new HSSFRichTextString("Tweets!!!")); fila = hoja.createRow(9); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString("IdTweet")); celda = fila.createCell(2); celda.setCellValue(new HSSFRichTextString("Cuenta")); celda = fila.createCell(3); celda.setCellValue(new HSSFRichTextString("Tweet")); celda = fila.createCell(4); celda.setCellValue(new HSSFRichTextString("Geolocation")); celda = fila.createCell(5); celda.setCellValue(new HSSFRichTextString("Place")); celda = fila.createCell(6); celda.setCellValue(new HSSFRichTextString("Retweets")); celda = fila.createCell(7); celda.setCellValue(new HSSFRichTextString("Favoritos")); Paging paging = new Paging(1, 1000); ResponseList<Status> s = twitter.getUserTimeline(u.getId(), paging); int i = 0; int filaNum = 10; for (Status st : s) { BasicDBObject obj = new BasicDBObject(); obj.append("idTweet", s.get(i).getId() + ""); obj.append("Cuenta", u.getName()); obj.append("Tweet", s.get(i).getText()); obj.append("Geolocation", s.get(i).getGeoLocation()); obj.append("Place", s.get(i).getPlace()); obj.append("Reteews", s.get(i).getRetweetCount()); obj.append("Favoritos", s.get(i).getFavoriteCount()); fila = hoja.createRow(filaNum); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(s.get(i).getId() + "")); celda = fila.createCell(2); celda.setCellValue(new HSSFRichTextString(u.getName())); celda = fila.createCell(3); celda.setCellValue(new HSSFRichTextString(s.get(i).getText())); celda = fila.createCell(4); celda.setCellValue(new HSSFRichTextString(s.get(i).getGeoLocation() + "")); celda = fila.createCell(5); celda.setCellValue(new HSSFRichTextString(s.get(i).getPlace() + "")); celda = fila.createCell(6); celda.setCellValue(new HSSFRichTextString(s.get(i).getRetweetCount() + "")); celda = fila.createCell(7); celda.setCellValue(new HSSFRichTextString(s.get(i).getFavoriteCount() + "")); i++; filaNum++; datos.insert(obj); } FileOutputStream elFichero = new FileOutputStream("Metricas_Twitter.xls"); libro.write(elFichero); elFichero.close(); /********************************/ System.out.println(i); //User usuario = twitter.showUser("@aaron21007"); // List<Status> statuses = twitter.getHomeTimeline(); // System.out.println("Showing home timeline."); // for (Status status : statuses) { // System.out.println(status.getUser().getName() + ":" + // status.getText()); // } // Twitter unauthenticatedTwitter = new TwitterFactory(cb.build()).getInstance(); // // List<String> listaTweets = new ArrayList(); // List<Long> ListaRettewts = new ArrayList(); // List<Integer> ListaFavoritos = new ArrayList(); // List<Integer> ListaMenciones = new ArrayList(); // List<Date> ListaFecha = new ArrayList(); // List<Long> ListaIds = new ArrayList(); //// // User usuario = unauthenticatedTwitter.showUser("@aaron21007"); // List<Status> ret = unauthenticatedTwitter.getRetweetsOfMe(); // List<Status> favoritos = unauthenticatedTwitter.getFavorites(); // Paging paging = new Paging(1, 1000); // ResponseList<Status> statuses = unauthenticatedTwitter.getUserTimeline(usuario.getId(), paging); // // // for (Status sta : statuses) { // // ListaIds.add(Long.valueOf(sta.getId())); // listaTweets.add(sta.getText()); // ListaRettewts.add(Long.valueOf(Long.parseLong(sta.getRetweetCount() + ""))); // ListaMenciones.add(Integer.valueOf(sta.getUserMentionEntities().length)); // ListaFecha.add(sta.getCreatedAt()); // ListaFavoritos.add(Integer.valueOf(sta.getFavoriteCount())); // System.out.println(sta.getText()); // // } // // // // // } catch (Exception e) { System.err.println("Fallo................." + e); } }
From source file:twitter.signin.java
public void initConfig() { if (System.getenv("OPENSHIFT_APP_NAME") != null) { twitter_consumer_key = "tansiongmmin"; twitter_consumer_secret = "miguelRiigen"; System.out.println("tw33tboard"); } else {/* w ww . j av a 2 s .c o m*/ System.out.println("localhost"); } ConfigurationBuilder cb = new ConfigurationBuilder(); System.out.println(twitter_consumer_key); cb.setJSONStoreEnabled(true); cb.setDebugEnabled(true).setOAuthConsumerKey(twitter_consumer_key) .setOAuthConsumerSecret(twitter_consumer_secret); tf = new TwitterFactory(cb.build()); twitter = tf.getInstance(); }
From source file:twitter.TweetGet.java
public void query(String queryString) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("2MZnm7LM7Ik9W3hzcXJOBaNER") .setOAuthConsumerSecret("0GER2kH3o1gOAyfPEDd870Iiuiu6XbQDayAXWfUBxU5APg4Le6") .setOAuthAccessToken("18972247-HgBP0djVaLw4U9fSX4lUdhKpZcqsJIAgnUCW3DRS5") .setOAuthAccessTokenSecret("bn8EQoOyGSRVUNX6elTmX9Wt9jiFJaxDaCZDk3U3hQB0g"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); Query query = new Query(queryString); query.setCount(20);/*from w w w.ja v a 2s. co m*/ QueryResult result; try { result = twitter.search(query); tweets = result.getTweets(); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); } }
From source file:twitter.TweetGet.java
public void getTweetFromUser(String username) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("2MZnm7LM7Ik9W3hzcXJOBaNER") .setOAuthConsumerSecret("0GER2kH3o1gOAyfPEDd870Iiuiu6XbQDayAXWfUBxU5APg4Le6") .setOAuthAccessToken("18972247-HgBP0djVaLw4U9fSX4lUdhKpZcqsJIAgnUCW3DRS5") .setOAuthAccessTokenSecret("bn8EQoOyGSRVUNX6elTmX9Wt9jiFJaxDaCZDk3U3hQB0g"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); try {/*from w ww . ja v a 2 s.co m*/ tweets = twitter.getUserTimeline(username); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); } }