List of usage examples for twitter4j.conf ConfigurationBuilder setDebugEnabled
public ConfigurationBuilder setDebugEnabled(boolean debugEnabled)
From source file:twittterbot08.TwittterBot08.java
/** * @param consumerKey/* ww w . ja va 2 s . co m*/ * @param consumerSecret * @param accessToken * @param accessTokenSecret * @return */ public Twitter intializeToken(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret) { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setDebugEnabled(true).setOAuthConsumerKey(consumerKey) .setOAuthConsumerSecret(consumerSecret).setOAuthAccessToken(accessToken) .setOAuthAccessTokenSecret(accessTokenSecret); Configuration configuration = configurationBuilder.build(); if (configuration != null) System.out.println("Configuration is Authenticated!"); TwitterFactory twitterFactory = new TwitterFactory(configuration); Twitter twitter = twitterFactory.getInstance(); return twitter; }
From source file:twittynumnum.TwittyNumNum.java
public static void main(String[] args) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("6id0aTmQrXrfnijhEsC5wfzTO") .setOAuthConsumerSecret("E8A8nvssRUvQ0B9Td32L8hW4wyMyZwPQeAPsvj1EF1WK4HUTou") .setOAuthAccessToken("4350904703-rrfWDlkfRi5l2iwKj1EMpbzxmXu44aqfPL9LOlX") .setOAuthAccessTokenSecret("dS3dT6JNDD1ih6EHXCnBrBm7vDrMWFjcDCupyyiL6RkEu"); //TwitterFactory tf = new TwitterFactory(cb.build()); //Twitter twitter = tf.getInstance(); //BackwardGrinder backy = new BackwardGrinder(twitter); // backy.grind("#glutenfree"); PrintWriter out;/*from ww w .jav a 2s. c om*/ try { out = new PrintWriter("data/#DebatRegionales.txt"); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); FutureListener future = new FutureListener(twitterStream, out); String[] keywords = { "#Paris" }; future.listen(keywords); } catch (FileNotFoundException ex) { Logger.getLogger(TwittyNumNum.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ua.group06.logic.TwitterAuthentication.java
public String getauthenticationURL(/*String requestURL*/) throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); // cb.setApplicationOnlyAuthEnabled(true); //cb.setOAuth2TokenType(token.getTokenType()); //cb.setOAuth2AccessToken(token.getAccessToken()); cb.setDebugEnabled(true).setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); this.twitter = twitter; //request.setAttribute("twitter", twitter); RequestToken requestToken = twitter.getOAuthRequestToken(/*requestURL*/); this.requestToken = requestToken; //request.getSession().setAttribute("requestToken", requestToken); return requestToken.getAuthenticationURL(); }
From source file:uniandes.edu.twitterreader.TwitterApp.java
public TwitterApp() { // Twitter Configuration ConfigurationBuilder cf = new ConfigurationBuilder(); cf.setDebugEnabled(true).setOAuthConsumerKey("Pjh11zSaQp7uI4Qe6HZrnXp5f") .setOAuthConsumerSecret("dCT2Z85JQ0B9FPafVrbEP26cC4dGduMkQeRT29YIU4Mhl8bhk0") .setOAuthAccessToken("105491840-OzLXnQyvNrpfm7pp6X0b6olTDWKKWmxvdhlQnA2a") .setOAuthAccessTokenSecret("edrCvTf2AOo7xIpuBwFNLY5GS0Dbx35KbFygMzs17hvrY"); cf.setJSONStoreEnabled(true);//from www .j a va2s. c om TwitterFactory tf = new TwitterFactory(cf.build()); twitter = tf.getInstance(); // Mongo connection mongoDB = new MongoClient(DB_SERVER, DB_PORT).getDatabase(DB_NAME); if (mongoDB.getCollection(COLLECTION_NAME) == null) { mongoDB.createCollection(COLLECTION_NAME); } mongoCollection = mongoDB.getCollection(COLLECTION_NAME); }
From source file:uta.ak.CollectTweets.java
public void collectTweetsByFileList(String sinceDate, String untilDate, String tag) { try {//www . ja v a2 s. c o m // The factory instance is re-useable and thread safe. System.out.println("Start to collect tweets from :"); Set<String> mediaList = new HashSet<String>(); Resource res = new ClassPathResource("new-social-meida-list.txt"); // File stopwords=res.getFile(); // File stopwords=new File("/Users/zhangcong/dev/corpus/StopWordTable2.txt"); InputStreamReader isr = new InputStreamReader(res.getInputStream()); // File medias=new File(path); // BufferedReader mdsreader = new BufferedReader(new FileReader(medias)); BufferedReader mdsreader = new BufferedReader(isr); String tempString = mdsreader.readLine(); while ((tempString = mdsreader.readLine()) != null) { System.out.println(tempString.toLowerCase()); mediaList.add(tempString.toLowerCase()); } ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("LuhVZOucqdHX6x0lcVgJO6QK3") .setOAuthConsumerSecret("6S7zbGLvHMXDMgRXq7jRIA6QmMpdI8i5IJNpnjlB55vpHpFMpj") .setOAuthAccessToken("861637891-kLunD37VRY8ipAK3TVOA0YKOKxeidliTqMtNb7wf") .setOAuthAccessTokenSecret("vcKDxs6qHnEE8fhIJr5ktDcTbPGql5o3cNtZuztZwPYl4"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); /* Connection con = null; //MYSQL Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/USTTMP", "root", "root.123"); //MYSQL System.out.println("connection yes"); String insertSQL="INSERT INTO c_rawtext(mme_lastupdate, mme_updater, title, text, tag, text_createdate) " + "VALUES (NOW(), \"AK\", ?, ?, ?, ?)"; PreparedStatement insertPS = con.prepareStatement(insertSQL); */ //?usttmp?? String restUrl = "http://192.168.0.103:8991/usttmp_textreceiver/rest/addText"; Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 1); SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (String mediastr : mediaList) { Query query = new Query("from:" + mediastr); query.setSince(sinceDate); query.setUntil(untilDate); query.setCount(100); query.setLang("en"); QueryResult result = twitter.search(query); for (Status status : result.getTweets()) { System.out.println("@" + status.getUser().getScreenName() + " | " + status.getCreatedAt().toString() + ":" + status.getText()); System.out.println("Inserting the record into the table..."); String formattedDate = format1.format(status.getCreatedAt()); /* insertPS.setString (1, status.getUser().getScreenName()); insertPS.setString (2, status.getText()); insertPS.setString (3, tag); insertPS.setString (4, formattedDate); insertPS.addBatch();*/ // if(null!=status.getText()){ // break; // } String interfaceMsg = "<message> " + " <title> " + ((null != status.getUser().getScreenName()) ? status.getUser().getScreenName() : "NO TITLE") + " </title> " + " <text> " + StringEscapeUtils.escapeXml10(status.getText()) + " </text> " + " <textCreatetime> " + formattedDate + " </textCreatetime> " + " <tag> " + tag + " </tag> " + "</message>"; // String restUrl="http://127.0.0.1:8991/usttmp_textreceiver/rest/addText"; RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_XML); headers.setAccept(Arrays.asList(MediaType.TEXT_XML)); // headers.setContentLength(); HttpEntity<String> entity = new HttpEntity<String>(interfaceMsg, headers); ResponseEntity<String> resresult = restTemplate.exchange(restUrl, HttpMethod.POST, entity, String.class); System.out.println(resresult.getBody()); if (resresult.getBody().contains("<result>failed</result>")) { throw new RuntimeException("response message error"); } } } // System.out.println("Start to insert records..."); // insertPS.clearParameters(); // int[] results = insertPS.executeBatch(); } catch (Exception te) { te.printStackTrace(); System.out.println("Failed: " + te.getMessage()); System.exit(-1); } }
From source file:uta.ak.CollectTweets.java
public void collectTweetsByKeyWords(String keyWords, String sinceDate, String untilDate, String tag) { try {//from ww w .ja v a2 s . com ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("LuhVZOucqdHX6x0lcVgJO6QK3") .setOAuthConsumerSecret("6S7zbGLvHMXDMgRXq7jRIA6QmMpdI8i5IJNpnjlB55vpHpFMpj") .setOAuthAccessToken("861637891-kLunD37VRY8ipAK3TVOA0YKOKxeidliTqMtNb7wf") .setOAuthAccessTokenSecret("vcKDxs6qHnEE8fhIJr5ktDcTbPGql5o3cNtZuztZwPYl4"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); Connection con = null; //MYSQL Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/USTTMP", "root", "root.123"); //MYSQL System.out.println("connection yes"); String insertSQL = "INSERT INTO c_rawtext(mme_lastupdate, mme_updater, title, text, tag, text_createdate) VALUES (NOW(), \"AK\", ?, ?, ?, ?)"; PreparedStatement insertPS = con.prepareStatement(insertSQL); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 1); SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd"); Query query = new Query(keyWords); query.setSince(sinceDate); query.setUntil(untilDate); query.setCount(100); query.setLang("en"); QueryResult result = twitter.search(query); for (Status status : result.getTweets()) { // System.out.println("@" + status.getUser().getScreenName() + // " | " + status.getCreatedAt().toString() + // ":" + status.getText()); // System.out.println("Inserting the record into the table..."); String formattedDate = format1.format(status.getCreatedAt()); insertPS.setString(1, status.getUser().getScreenName()); insertPS.setString(2, status.getText()); insertPS.setString(3, tag); insertPS.setString(4, formattedDate); insertPS.addBatch(); } System.out.println("Start to insert records..."); insertPS.clearParameters(); int[] results = insertPS.executeBatch(); } catch (Exception te) { te.printStackTrace(); System.out.println("Failed: " + te.getMessage()); System.exit(-1); } }
From source file:util.UtilConfig.java
public static Twitter getTwitterInstance() { if (twitter == null) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET) .setOAuthAccessToken(ACCESS_TOKEN).setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance();/*from w w w. j a v a2 s . c om*/ } return twitter; }
From source file:views.MeetingRoomPanel.java
public void initTimeline() { timelineFrame = new JFrame("@SIM_IST Timeline"); timelineFrame.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); timelineTweets = new JTextArea(); Font font = new Font("Gotham Narrow", Font.BOLD, 12); timelineTweets.setFont(font);//w w w .j av a 2 s . c om timelineTweets.setEditable(false); timelineScrollPane = new JScrollPane(timelineTweets); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.ipady = 200; c.gridx = 0; c.gridy = 0; c.gridwidth = 3; timelineFrame.add(timelineScrollPane, c); KeyReader keys = new KeyReader(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(keys.getConsumerKey()) .setOAuthConsumerSecret(keys.getConsumerSecret()).setOAuthAccessToken(keys.getAccessToken()) .setOAuthAccessTokenSecret(keys.getAccessTokenSecret()); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); try { System.out.println("timeline retreval worked"); List<Status> statuses = twitter.getHomeTimeline(); for (Status status : statuses) { timelineTweets .append("@" + status.getUser().getScreenName() + " : " + status.getText() + "\n" + "\n"); timelineTweets.setLineWrap(true); timelineTweets.setWrapStyleWord(true); timelineTweets.setCaretPosition(0); System.out.println("@" + status.getUser().getName() + " : " + status.getText()); } } catch (TwitterException te) { System.out.print("timeline retreval failed"); te.printStackTrace(); } timelineFrame.pack(); timelineFrame.setSize(600, 300); timelineFrame.setDefaultCloseOperation(EXIT_ON_CLOSE); timelineFrame.setLocationRelativeTo(null); timelineFrame.setVisible(true); }
From source file:wap.twitter.model.TwitterUtility.java
public static TwitterFactory config() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("fDyslJSP3mUbBXRfaJliPG1jd") .setOAuthConsumerSecret("KOJU7mo0Xs3s1YvheA6xBlqElGBuvUD1SpoB2HVY2b9b7iq50t") .setOAuthAccessToken("800805041502240768-0UqQQLOpC4WKPhdAzp6A0QCUoJKb8UP") .setOAuthAccessTokenSecret("dCyn31WXBDna2h98V8A4T1Rgw6uwOafXkwonDEsF4zqFr"); TwitterFactory tf = new TwitterFactory(cb.build()); return tf;//from w w w . ja va2 s.com }
From source file:wap.twitter.model.TwitterUtility.java
private static Integer getTrendLocationId(String locationName) { int idTrendLocation = 0; try {//from w ww. j a va2 s .co m ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("yourConsumerKey") .setOAuthConsumerSecret("yourConsumerSecret").setOAuthAccessToken("yourOauthToken") .setOAuthAccessTokenSecret("yourOauthTokenSecret"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); ResponseList<Location> locations; locations = twitter.getAvailableTrends(); for (Location location : locations) { if (location.getName().toLowerCase().equals(locationName.toLowerCase())) { idTrendLocation = location.getWoeid(); break; } } if (idTrendLocation > 0) { return idTrendLocation; } return null; } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get trends: " + te.getMessage()); return null; } }