List of usage examples for twitter4j.conf ConfigurationBuilder ConfigurationBuilder
ConfigurationBuilder
From source file:org.wso2.cep.uima.demo.TweetExtractor.java
License:Open Source License
/*** * Method to set up the API keys for the configuration builder *///from w ww . jav a 2 s .c o m private void buildConfiguration() throws IOException, SAXException, ParserConfigurationException { cb = new ConfigurationBuilder(); Logger.getLogger(TweetExtractor.class).debug("Building Configuration"); TwitterConfiguration config = TwitterConfigurationBuilder.getTwitterConfiguration(); String consumerKey = config.getConsumerKey(); String consumerSecret = config.getConsumerSecret(); String accessToken = config.getAccessToken(); String accessTokenSecret = config.getAccessTokenSecret(); userToSearch = config.getUserToSearch(); maxTweets = config.getMaxTweets(); logger.info("Maximum Number of Tweets to extract: " + maxTweets); if (consumerKey == null || consumerSecret == null || accessToken == null || accessTokenSecret == null) { logger.error("Twitter API Keys have not been set properly in twitterConfig.xml"); throw new NullPointerException("TWitter API Keys not set"); } cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret); }
From source file:org.wso2.cep.uima.demo.TwitterStreamer.java
License:Open Source License
/*** * Method to set up the API keys for the configuration builder *///from w w w . j a v a 2 s . c o m private void buildConfiguration() { cb = new ConfigurationBuilder(); logger.debug("Building Configuration"); if (consumerKey == null || consumerSecret == null || accessToken == null || accessTokenSecret == null) { logger.error("Twitter API keys not set properly in twitterConfig.xml"); throw new NullPointerException("TWitter API Keys not set"); } cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret); }
From source file:Origin.Mypage.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, TwitterException { response.setContentType("text/html;charset=UTF-8"); /* TODO output your page here. You may use following sample code. */ ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);// ww w . j a v a 2s . c om cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); cb.setOAuthAccessToken(ACCESS_TOKEN); cb.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); User user = twitter.verifyCredentials(); request.setCharacterEncoding("UTF-8"); HttpSession hs = request.getSession(); UserData ud = (UserData) hs.getAttribute("ud"); String search = ud.getLine() + "?"; //String search= request.getParameter("searchtweet"); Query query = new Query(); query.setCount(100); query.setQuery(search); QueryResult queryresult = null; try { queryresult = twitter.search(query); } catch (TwitterException e1) { e1.printStackTrace(); } ArrayList<String> userID = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { userID.add(tweet.getUser().getScreenName()); } ArrayList<String> profileimg = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { profileimg.add(tweet.getUser().getBiggerProfileImageURL()); } ArrayList<String> username = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { username.add(tweet.getUser().getName() + "<br>" + "@" + tweet.getUser().getScreenName()); } ArrayList<String> usernameURL = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { username.add(tweet.getUser().getURL()); } SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); ArrayList<String> resulttweet = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { resulttweet.add(tweet.getText() + "<br>" + sdf.format(tweet.getCreatedAt())); } request.setAttribute("search", search); request.setAttribute("userID", userID); request.setAttribute("profileimg", profileimg); request.setAttribute("username", username); request.setAttribute("resulttweet", resulttweet); request.setAttribute("usernameURL", usernameURL); request.getRequestDispatcher("/mypage.jsp").forward(request, response); }
From source file:Origin.Searchtweet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, TwitterException { response.setContentType("text/html;charset=UTF-8"); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);/* ww w . j a v a 2 s .co m*/ cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); cb.setOAuthAccessToken(ACCESS_TOKEN); cb.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); User user = twitter.verifyCredentials(); request.setCharacterEncoding("UTF-8"); String search = "?" + request.getParameter("searchtweet"); //String search= request.getParameter("searchtweet"); Query query = new Query(); query.setCount(100); query.setQuery(search); QueryResult queryresult = null; try { queryresult = twitter.search(query); } catch (TwitterException e1) { e1.printStackTrace(); } ArrayList<String> userID = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { userID.add(tweet.getUser().getScreenName()); } ArrayList<String> profileimg = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { profileimg.add(tweet.getUser().getBiggerProfileImageURL()); } ArrayList<String> username = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { username.add(tweet.getUser().getName() + "<br>" + "@" + tweet.getUser().getScreenName()); } ArrayList<String> usernameURL = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { username.add(tweet.getUser().getURL()); } SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); ArrayList<String> resulttweet = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { resulttweet.add(tweet.getText() + "<br>" + sdf.format(tweet.getCreatedAt())); } request.setAttribute("search", search); request.setAttribute("userID", userID); request.setAttribute("profileimg", profileimg); request.setAttribute("username", username); request.setAttribute("resulttweet", resulttweet); request.setAttribute("usernameURL", usernameURL); request.getRequestDispatcher("/searchtweet.jsp").forward(request, response); }
From source file:Origin.Timeline.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);//from w ww. j a v a 2 s . c o m cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); cb.setOAuthAccessToken(ACCESS_TOKEN); cb.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET); try { Twitter twitter = new TwitterFactory(cb.build()).getInstance(); User user = twitter.verifyCredentials(); Paging paging = new Paging(1, 200); ResponseList<Status> userstatus = twitter.getHomeTimeline(paging); request.setAttribute("userstatus", userstatus); request.getRequestDispatcher("/timeline.jsp").forward(request, response); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }
From source file:Origin.Tweet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, TwitterException { response.setContentType("text/html;charset=UTF-8"); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);/*from ww w . j av a 2s . c om*/ cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); cb.setOAuthAccessToken(ACCESS_TOKEN); cb.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET); try { Twitter twitter = new TwitterFactory(cb.build()).getInstance(); User user = twitter.verifyCredentials(); HttpSession session = request.getSession(); request.setCharacterEncoding("UTF-8"); //String tweet = encode(request.getParameter("tweet")); String tweet = request.getParameter("tweet"); Status status = twitter.updateStatus(tweet); session.setAttribute("tweet", tweet); request.getRequestDispatcher("/tweet.jsp").forward(request, response); } catch (TwitterException e1) { e1.printStackTrace(); } }
From source file:Principal.Tracker_Twitter.java
License:Minecraft Mod Public
public void guardarResultados_Twitter(List<ObjetoBuscar> lista, BD base, int contadorBase, int TokenIndice) throws NoSuchAlgorithmException, KeyManagementException { int nuevoContadorBase = 0; if (contadorBase >= lista.size()) { System.out.println("Termino en:" + contadorBase); } else {//from ww w .jav a 2 s. c o m System.out.println("---------------------------------------------------------------------:P"); TrustManager[] trustAllCerts = { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String authType) { } } }; SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HostnameVerifier allHostsValid = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); System.out.println("Token : " + TokenIndice); System.out.println(consumerKey[TokenIndice]); try { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(consumerKey[TokenIndice]); cb.setOAuthConsumerSecret(this.consumerSecret[TokenIndice]); cb.setOAuthAccessToken(this.token[TokenIndice]); cb.setOAuthAccessTokenSecret(this.tokenSecret[TokenIndice]); Twitter unauthenticatedTwitter = new TwitterFactory(cb.build()).getInstance(); for (int numtTweets = contadorBase; numtTweets < contadorBase + 5; numtTweets++) { if (((ObjetoBuscar) lista.get(numtTweets)).getUrl().equals("") || ((ObjetoBuscar) lista.get(numtTweets)).getUrl() == null) { } else { System.out.println("Usuario: " + ((ObjetoBuscar) lista.get(numtTweets)).getUrl()); String usuariosinArroba = ((ObjetoBuscar) lista.get(numtTweets)).getUrl().replace("@", ""); System.out.println("" + usuariosinArroba); try { User usuario = unauthenticatedTwitter.showUser(usuariosinArroba); List<Status> ret = unauthenticatedTwitter.getRetweetsOfMe(); List<Status> favoritos = unauthenticatedTwitter.getFavorites(); Paging paging = new Paging(1, 1000); ResponseList<Status> statuses = unauthenticatedTwitter.getUserTimeline(usuario.getId(), paging); System.out.println("Followers: " + usuario.getFollowersCount()); System.out.println("Yo sigo: " + usuario.getFriendsCount()); 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(); 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())); } for (int i = 0; i < listaTweets.size(); i++) { base.guardarTrackTwitter_Log((Long) ListaIds.get(i), ((ObjetoBuscar) lista.get(numtTweets)).getUrl(), (String) listaTweets.get(i), (Date) ListaFecha.get(i), (Long) ListaRettewts.get(i), ((Integer) ListaFavoritos.get(i)).intValue(), ((Integer) ListaMenciones.get(i)).intValue()); } } catch (Exception e) { System.err.println("Entro al Try por :" + e); } nuevoContadorBase = numtTweets; } } System.out.println("Numero de Contador Base:" + nuevoContadorBase); guardarResultados_Twitter(lista, base, nuevoContadorBase + 1, TokenIndice + 1); } catch (NumberFormatException e) { System.err.println("Fallo por :" + e); } } }
From source file:project.mum.TwitterTrend.java
public List getTrends(double longi, double lati) throws TwitterException { List availableTrends = new ArrayList<String>(); ConfigurationBuilder cf = new ConfigurationBuilder(); cf.setDebugEnabled(true).setOAuthConsumerKey("TBFU8jBXiIOEde0cnSglw2m7B") .setOAuthConsumerSecret("c0tJVVvGgpY2rI1Ol5qmxzMpB1MiBx8PGlLNPG7TYAAVXwYVvL") .setOAuthAccessToken("1148852892-OR8mM62nOH4WPJf991X5bCp4zVKT2EU57fBmjWQ") .setOAuthAccessTokenSecret("zpXLqUxlkHZT58RDbGEPLnXVB3Kpwp7d8Z4CKb4X4UJW6"); TwitterFactory tf = new TwitterFactory(cf.build()); twitter4j.Twitter twitter = tf.getInstance(); ResponseList<Location> locations; List<MyTrend> myTrend = new ArrayList<MyTrend>(); MyTrend myTwitterTrend;/*from w w w . j a va2 s . c o m*/ GeoLocation geo = new GeoLocation(longi, lati); locations = twitter.getClosestTrends(geo); Trends trends = twitter.getPlaceTrends(locations.get(0).getWoeid()); int count = 0; for (Trend trend : trends.getTrends()) { if (count < 5) { myTwitterTrend = new MyTrend(trend.getName(), trend.getURL()); myTrend.add(myTwitterTrend); count++; availableTrends.add(trend.getName()); } } System.out.println(" available Trends :" + availableTrends); return myTrend; }
From source file:proxectotwitt.Metodo.java
/** * Ponemos nuestros datos para poder acceder a nuestra cuenta, codigos de twitter developers *//*from w ww . j a va 2 s.c om*/ public static void acceso() { cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); cb.setOAuthConsumerKey("nipbbZAo4YYvZTiJ9eTqoweor"); cb.setOAuthConsumerSecret("bBPcuZLVDzrhvcRYkLHgoEAy7TGgzgJtrTtYn4zL2UowgVEyHn"); cb.setOAuthAccessToken("848794118230769664-eRC9ShFPcKgnOZh9U6hRQOSfHGISCyY"); cb.setOAuthAccessTokenSecret("or2LmVjEXELuaRtjJSPDH1CMlQCWIH4rbPfGGMRQ9nDho"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance(); }
From source file:proyectotwitter.AppTwitter.java
public void connect() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("h5QMQS9cq1YDXlgBSZFOoJnkz") .setOAuthConsumerSecret("lCnodmJSIPHVhuxpZlnKe88TQDgwO9OGYCLpdR5gpVdKIiorCb") .setOAuthAccessToken("843739695091802112-z9wPdDceVHCkzQT9xgfUcPyA3scb7b6") .setOAuthAccessTokenSecret("1cygSjbP9gyZ0aGJep8sK2603tcZ6yaILM843nQpHdPaL"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance();/* w ww . ja v a 2 s . co m*/ }