List of usage examples for twitter4j TwitterFactory TwitterFactory
public TwitterFactory(String configTreePath)
From source file:Controller.DetailsOffreController.java
@FXML void partagersurtwitter(ActionEvent event) throws TwitterException { OffreService offreService = new OffreService(); AfficherToutesOffresController z = new AfficherToutesOffresController(); Offre x = offreService.findById(Integer.parseInt(AfficherToutesOffresController.getLabelid())); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("zFrvXiT4O6bPh7wtfX2qpxTJM") .setOAuthConsumerSecret("pZeG2yJ71HYSu3y8MC4sbOcAeKstRKmp8bVKfCOmxnd4QjsKmC") .setOAuthAccessToken("3345656831-F533Ns9kdMPI6GfmHwiVor3BUHM6kYJn4WO4xhq") .setOAuthAccessTokenSecret("1hWrntZlel0gOju0xOEVf2t5kRo2CjSp5H75sieOUfT89"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter4j.Twitter tw = tf.getInstance(); String pathphoto = x.getPhoto(); String nomphoto = pathphoto.substring(62); System.out.println(nomphoto); File file = null;/*from w w w . j a va 2 s. c o m*/ file = new File(x.getPhoto()); String StatusMessage = (x.getPtvente().getNom() + "\n" + x.getDescription() + "\n" + x.getTaux_remise()); StatusUpdate status = new StatusUpdate(StatusMessage); status.setMedia(file); tw.updateStatus(status); }
From source file:CR.CERA.SensoryMotor.Twitter.Authorization.java
public Authorization() throws IOException, TwitterException { // w ww. j ava2s . c o m ConfigurationBuilder configBuilder = new ConfigurationBuilder(); configBuilder.setDebugEnabled(true) .setOAuthConsumerKey("String con el Consumer key de la aplicacin (Ver en la web de Twitter Developer)") .setOAuthConsumerSecret("String con el Consumer secret de la aplicacin (Ver en la web de Twitter Developer)"); Twitter OAuthTwitter = new TwitterFactory(configBuilder.build()).getInstance(); RequestToken requestToken = null; AccessToken accessToken = null; String url = null; }
From source file:crawler.DataSearch.java
License:Apache License
public DataSearch(String[] keywords) { this.keywords.addAll(Arrays.asList(keywords)); OA = new OAuthUser(); twitter = new TwitterFactory(OA.build(Settings.ConsumerKey.get(0), Settings.ConsumerSecret.get(0), Settings.AccessToken.get(0), Settings.AccessSecret.get(0))).getInstance(); }
From source file:crawler.DataSearch.java
License:Apache License
public void collectNewTweets() { while (keywords.size() > 0) { String hash = keywords.get(0); Query query = new Query(hash); query.setCount(Settings.searchTweetNo); QueryResult result;/* w ww . j av a 2 s . c om*/ try { result = twitter.search(query); List<Status> tweets = result.getTweets(); if (tweets.size() == 0) TwitterCrawler.TFFreq.remove(hash); for (Status status : tweets) { //System.out.println("{"+hash+"}["+status.getCreatedAt().toString()+"]- [USER: " + status.getUser().getScreenName() + "] - " + status.getText()); String temp; if (trash(status.getText())) { if (Settings.limitTime) { long currentTime = System.currentTimeMillis(); long tweetTime = status.getCreatedAt().getTime(); if (currentTime - tweetTime > Settings.timeLimit) continue; } if (hashtext.containsKey(hash)) temp = hashtext.get(hash) + status.getText(); else temp = status.getText(); hashtext.put(hash, temp); } } //System.out.println("{"+hash+"} with "+tweets.size()+"tweets"); keywords.remove(0); } catch (TwitterException e) { if (e.getErrorCode() == 88) { System.out.println("Using other keys???"); String ConsumerKey_temp = Settings.ConsumerKey.get(0); String ConsumerSecret_temp = Settings.ConsumerSecret.get(0); String AccessToken_temp = Settings.AccessToken.get(0); String AccessSecret_temp = Settings.AccessSecret.get(0); Settings.ConsumerKey.remove(ConsumerKey_temp); Settings.ConsumerSecret.remove(ConsumerSecret_temp); Settings.AccessToken.remove(AccessToken_temp); Settings.AccessSecret.remove(AccessSecret_temp); twitter = new TwitterFactory( OA.build(Settings.ConsumerKey.get(0), Settings.ConsumerSecret.get(0), Settings.AccessToken.get(0), Settings.AccessSecret.get(0))).getInstance(); Settings.ConsumerKey.add(Settings.ConsumerKey.size(), ConsumerKey_temp); Settings.ConsumerSecret.add(Settings.ConsumerSecret.size(), ConsumerSecret_temp); Settings.AccessToken.add(Settings.AccessToken.size(), AccessToken_temp); Settings.AccessSecret.add(Settings.AccessSecret.size(), AccessSecret_temp); System.out.println("**************************************************************"); System.out.println("[" + ConsumerKey_temp + "] to [" + Settings.ConsumerKey.get(0) + "]"); System.out.println("[" + ConsumerSecret_temp + "] to [" + Settings.ConsumerSecret.get(0) + "]"); System.out.println("[" + AccessToken_temp + "] to [" + Settings.AccessToken.get(0) + "]"); System.out.println("[" + AccessSecret_temp + "] to [" + Settings.AccessSecret.get(0) + "]"); System.out.println("**************************************************************"); continue; } e.printStackTrace(); } } }
From source file:crawler.TwitterFeed.java
/** * *//*www . ja v a 2s . c o m*/ public void get_tweets() throws SQLException { CSVReader cr = new CSVReader(); ArrayList<String> names = new ArrayList<>(); Map<String, String> name_ticker; names = cr.get_company_names(tickers); System.out.println(names); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey("WNSycI2GS33ZAwHJ9Fb4A"); cb.setOAuthConsumerSecret("BBWeSThT3ZV2g9c5BDuUduDyNAWyzouMI0XjQy7KUc"); cb.setOAuthAccessToken("1852271029-SLfE061bImfcRxWQZpy1pAgpEkfFhg3757Q9JRf"); cb.setOAuthAccessTokenSecret("1uPSfYPbaENtXFYWsryBIAHnUsmG3pT6lGH0NzxTCGW7O"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); for (String s : names) { String[] temp; if (s.contains(",")) { temp = s.split(","); } else { temp = s.split(" "); } System.out.println( "--------------------------------------------------------------------------------------" + temp[0]); Query query = new Query("#" + temp[0]); query.lang("en"); int numberOfTweets = 500; long lastID = Long.MAX_VALUE; ArrayList<Status> tweets = new ArrayList<>(); while (tweets.size() < numberOfTweets) { if (numberOfTweets - tweets.size() > 100) { query.setCount(100); } else { query.setCount(numberOfTweets - tweets.size()); } try { QueryResult result = twitter.search(query); tweets.addAll(result.getTweets()); System.out.println("Gathered " + tweets.size() + " tweets"); for (Status t : tweets) { if (t.getId() < lastID) { lastID = t.getId(); } } } catch (TwitterException te) { System.out.println("Couldn't connect: " + te); } query.setMaxId(lastID - 1); } Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/CrawledData", "root", ""); for (int i = 0; i < tweets.size(); i++) { Status t = (Status) tweets.get(i); //GeoLocation loc = t.getGeoLocation(); String user = t.getUser().getScreenName(); String msg = t.getText(); String time = t.getCreatedAt().toString(); //if (loc!=null) { // Double lat = t.getGeoLocation().getLatitude(); // Double lon = t.getGeoLocation().getLongitude(); // System.out.println(i + " USER: " + user + " wrote: " + msg + " located at " + lat + ", " + lon); //} //else{ System.out.println(i + " USER: " + user + " wrote: " + msg + " at: " + time); //} try { Class.forName("com.mysql.jdbc.Driver"); PreparedStatement ps = con .prepareStatement("INSERT IGNORE INTO TwitterFeed VALUES (?,?,?,?,?)"); ps.setString(1, s); ps.setString(2, cr.get_ticker_from_company(s)); ps.setString(3, user); ps.setString(4, msg); ps.setString(5, time); int k = ps.executeUpdate(); if (k <= 0) { System.out.println("Entry Unsuccessful"); } else { System.out.println("Entry Successful"); } } catch (ClassNotFoundException | SQLException e) { System.out.println(e); } } con.close(); } }
From source file:crawling.FoundUsersBySearchGeo.java
License:Apache License
private static Twitter getOAuthTwitter() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true)//from w w w . j a v a 2 s . c o m /* .setOAuthConsumerKey("b81qmksOTVVMz9ZqjEVGsA") .setOAuthConsumerSecret("SYdycGH344dwM7Qt5BzDSiq8o3KepAtKC3XiaWIE") .setOAuthAccessToken("584842364-QOgpdKzRO2NVIoppceYkuSDquxyEa26FdSAXjkKc") .setOAuthAccessTokenSecret("oogO0og69qkRrLrk2zXGEE4oDYW2PeyZVss1IGPmOM"); */ /*.setOAuthConsumerKey("96vFsO7KxTojBCFWsig") .setOAuthConsumerSecret("zTxu00E7XlsKRgEz32FcTXrB5UhLEkSpZS1sK8n68w") .setOAuthAccessToken("591403328-85wymmBPZmGEwe8rXKog2HMzIup4tY8m2zU7NHg") .setOAuthAccessTokenSecret("kx9yya9NUDe1WQhYNDFKh1cg9fstm3RVptAUXlbA");*/ .setOAuthConsumerKey("fDD11KrH0qNAQqnCKeA5vQ") .setOAuthConsumerSecret("BDh7COGEqjz38jsXwY3HnElkXtW8xCRGDq5vTWERY68") .setOAuthAccessToken("562640944-BesiZJVB4X4liIbzOVrI1YPdxZYJSBkB8TMSNrY") .setOAuthAccessTokenSecret("5rLAkUCBXkt3Ijp2wrqfxSHsOYPpYyq3GYv7b62xI8"); //cb.setUseSSL(true); // This declaration is not needed in Twitter4J 4.0.2 return new TwitterFactory(cb.build()).getInstance(); }
From source file:crawling.FoundUsersBySearchHashtag.java
License:Apache License
private static Twitter getOAuthTwitter() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("Oo1Np62vR41MJTeVViKMmA") .setOAuthConsumerSecret("9e2ad6usWLJikjoI4yNuDQ85rrf9eRvfLmUDRBPtZ8") .setOAuthAccessToken("701461304-mbDoQtYqtSG9Q2RHLlSBUFEgRWbKE0CpViYowNXs") .setOAuthAccessTokenSecret("aWeao9VabuGfphGcH83SozAwI0hgmlmg3ptS5KGGVs"); /*cb.setDebugEnabled(true) .setOAuthConsumerKey(prop.getProperty("oauth.consumerKey")) .setOAuthConsumerSecret(prop.getProperty("oauth.consumerSecret")) .setOAuthAccessToken(prop.getProperty("oauth.accessToken")) .setOAuthAccessTokenSecret(prop.getProperty("oauth.accessTokenSecret"));*/ return new TwitterFactory(cb.build()).getInstance(); }
From source file:crawling.GetUserTimelineMulti.java
License:Apache License
private Twitter getOAuthTwitter(String[] auth) { if (auth.length != 4) { System.out.println("The auth info is invalid!"); System.exit(-1);// www .j ava2 s . c o m } ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(auth[0]).setOAuthConsumerSecret(auth[1]) .setOAuthAccessToken(auth[2]).setOAuthAccessTokenSecret(auth[3]); return new TwitterFactory(cb.build()).getInstance(); }
From source file:crawling.SearchTweetsHashtag.java
License:Apache License
private static Twitter getOAuthTwitter() { ConfigurationBuilder cb = new ConfigurationBuilder(); /*cb.setDebugEnabled(true) .setOAuthConsumerKey("Oo1Np62vR41MJTeVViKMmA") .setOAuthConsumerSecret("9e2ad6usWLJikjoI4yNuDQ85rrf9eRvfLmUDRBPtZ8") .setOAuthAccessToken("701461304-mbDoQtYqtSG9Q2RHLlSBUFEgRWbKE0CpViYowNXs") .setOAuthAccessTokenSecret("aWeao9VabuGfphGcH83SozAwI0hgmlmg3ptS5KGGVs"); *//*from w ww . j av a2s . c o m*/ cb.setDebugEnabled(true).setOAuthConsumerKey(prop.getProperty("oauth.consumerKey")) .setOAuthConsumerSecret(prop.getProperty("oauth.consumerSecret")) .setOAuthAccessToken(prop.getProperty("oauth.accessToken")) .setOAuthAccessTokenSecret(prop.getProperty("oauth.accessTokenSecret")); return new TwitterFactory(cb.build()).getInstance(); }
From source file:crawltweets2mongo.CrawlTweets2Mongo.java
public static void getTweetByQuery(boolean loadRecords, String keyword) { if (collection != null) { final String api_key = "your api key in here"; final String api_secret = "applied it from twitter website"; final String access_token = "applied token from twitter website"; final String access_token_secret = "applied it from twitter website"; // The factory instance is re-useable and thread safe. if (twitter == null) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(false).setOAuthConsumerKey(api_key).setOAuthConsumerSecret(api_secret) .setOAuthAccessToken(access_token).setOAuthAccessTokenSecret(access_token_secret); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance();//from w ww . j a v a 2 s .co m } threadMessage("Starting MessageLoop thread"); long startTime = System.currentTimeMillis(); Thread t = new Thread(new MonoThread(collection, twitter)); t.start(); threadMessage("Waiting for MessageLoop thread to finish"); // loop until MessageLoop // thread exits while (t.isAlive()) { try { t.join(28000); t.join(28000); t.join(28000); if (((System.currentTimeMillis() - startTime) > 1000 * 60 * 60) // long patience = 1000 * 60 * 60; && t.isAlive()) { threadMessage("Tired of waiting!"); t.interrupt(); t.join(); } } catch (InterruptedException ex) { Logger.getLogger(CrawlTweets2Mongo.class.getName()).log(Level.SEVERE, null, ex); } } threadMessage("Finally!"); } else { System.out.println("MongoDB is not Connected! Please check mongoDB intance running.."); } }