List of usage examples for twitter4j.conf ConfigurationBuilder ConfigurationBuilder
ConfigurationBuilder
From source file:twitter.crawler.TwitterCrawler.java
public static void main(String[] args) { try {// w w w. j a v a2 s . c o m // Authorise the library ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey("AhoydO8uSe4v8NEq7j2ISGFlq"); cb.setOAuthConsumerSecret("ptKEYwq3G9vpFkqAhvwFLSWFcBW8U1SfqycECwK4cH6wThVba6"); cb.setOAuthAccessToken("778240255577194496-taafqDIHebrg972oxT5kTqcNd3Uojod"); cb.setOAuthAccessTokenSecret("DMRmeRahnLJRvCBIGQGTaTzE6Pr3PAZMgMsfWIT5ue3PD"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); User user = twitter.verifyCredentials(); // Get main user long cursor = -1; // Print user profile System.out.println("@" + user.getScreenName()); System.out.println(user.getId()); System.out.println(user.getProfileImageURL()); System.out.println(user.getFriendsCount() + " friends."); System.out.println("-------"); // Print Home Timeline List<Status> statuses = twitter.getHomeTimeline(); System.out.println("Showing @" + user.getScreenName() + "'s home timeline."); for (Status status : statuses) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } //Print followers System.out.println("-------"); System.out.println("Showing Follwers:"); PagableResponseList<User> followers; //do //{ followers = twitter.getFollowersList(user.getScreenName(), cursor); for (User follower : followers) { System.out.println("@" + follower.getScreenName()); } //} //while ((cursor = followers.getNextCursor())!=-1); //Print follwees System.out.println("-------"); System.out.println("Showing Followees:"); PagableResponseList<User> followees; do { followees = twitter.getFriendsList(user.getScreenName(), cursor); for (User followee : followees) { System.out.println("@" + followee.getScreenName()); } } while ((cursor = followees.getNextCursor()) != -1); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }
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);//from ww w.ja v a 2s .co 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.Frame.java
/** * Creates new form Frame/*from w w w.ja v a2 s. c o m*/ */ public Frame() { initComponents(); squery = "#YOLO";//Este es el hashtag a buscar flag = true; //Nos conectamos a Mongo DB database = "twitter";//nombre de la base de datos collection = "twitts";//colleccion mongo = new MongoClient("localhost"); //Aqui van las llaves, las quite para que no se vieran publicas cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("").setOAuthConsumerSecret("").setOAuthAccessToken("") .setOAuthAccessTokenSecret(""); tf = new TwitterFactory(cb.build()); twitter = tf.getInstance(); timer = new Timer(); //Colecctamos twiits cada 10 segundos para que no se repitan timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { if (flag) getTwitters(); } }, 100, 10000); this.addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent e) { } @Override public void windowClosing(WindowEvent e) { mongo.close();//cerramos la conexion al cerrar la ventana } @Override public void windowClosed(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } }); }
From source file:twitter.login.java
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed try {//ww w . j a v a2s . com //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 v a2 s .com 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 {//from ww w . j a va 2 s . c om 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 ww w. ja va2s .com*/ 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 {/* w w w .ja v a 2 s . c om*/ tweets = twitter.getUserTimeline(username); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); } }
From source file:Twitter.Twitter.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("8e27WtNVhuIOt1EAyAdqV51Yk") .setOAuthConsumerSecret("dsgPVnwV53UwiPuAA5r0CbNykubjxmGHe7csf0Y1zGOV8KVe0r") .setOAuthAccessToken("4143520821-ZgULKYSyMRbrXytCvkmdGeXbd7L0bx4NOiM4fKC") .setOAuthAccessTokenSecret("jju1OwDCromI9r0QK1gU18MrFOkw1jsKFCQtXjFbv5G8A"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter4j.Twitter tw = tf.getInstance(); Status stat;/* w ww . j a v a 2s . co m*/ try { stat = tw.updateStatus(tweet.getText()); //System.out.println("twitter updated"); } catch (TwitterException ex) { Logger.getLogger(Twitter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:TwitterAnalytics.TwitterAPI.java
private TwitterAPI() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(consumerKey); builder.setOAuthConsumerSecret(consumeSecretKey); builder.setOAuthAccessToken(accessToken); builder.setOAuthAccessTokenSecret(accessSecretToken); Configuration configuration = builder.build(); TwitterFactory factory = new TwitterFactory(configuration); twitter = factory.getInstance();/*from w ww. j a v a2 s . c om*/ }