List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthConsumerKey
public ConfigurationBuilder setOAuthConsumerKey(String oAuthConsumerKey)
From source file:org.onepercent.utils.twitterstream.agent.src.main.java.com.cloudera.flume.source.TwitterSource.java
License:Apache License
/** * The initialization method for the Source. The context contains all the * Flume configuration info, and can be used to retrieve any configuration * values necessary to set up the Source. */// ww w. jav a2s . c om @Override public void configure(Context context) { consumerKey = context.getString(TwitterSourceConstants.CONSUMER_KEY_KEY); consumerSecret = context.getString(TwitterSourceConstants.CONSUMER_SECRET_KEY); accessToken = context.getString(TwitterSourceConstants.ACCESS_TOKEN_KEY); accessTokenSecret = context.getString(TwitterSourceConstants.ACCESS_TOKEN_SECRET_KEY); String keywordString = context.getString(TwitterSourceConstants.KEYWORDS_KEY, ""); if (keywordString.trim().length() == 0) { keywords = new String[0]; } else { keywords = keywordString.split(","); for (int i = 0; i < keywords.length; i++) { keywords[i] = keywords[i].trim(); } } String languageString = context.getString(TwitterSourceConstants.LANGUAGE_KEY, ""); if (languageString.trim().length() == 0) { languages = new String[0]; } else { languages = languageString.split(","); for (int i = 0; i < languages.length; i++) { languages[i] = languages[i].trim(); } } ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(consumerKey); cb.setOAuthConsumerSecret(consumerSecret); cb.setOAuthAccessToken(accessToken); cb.setOAuthAccessTokenSecret(accessTokenSecret); cb.setJSONStoreEnabled(true); cb.setIncludeEntitiesEnabled(true); twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); }
From source file:org.opennms.netmgt.notifd.MicroblogClient.java
License:Open Source License
public Twitter getTwitter(final String profile) { final MicroblogProfile mp = getProfile(profile); final ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setClientURL(mp.getServiceUrl()); if (!isEmpty(mp.getOauthConsumerKey())) builder.setOAuthConsumerKey(mp.getOauthConsumerKey()); if (!isEmpty(mp.getOauthConsumerSecret())) builder.setOAuthConsumerSecret(mp.getOauthConsumerSecret()); if (!isEmpty(mp.getOauthAccessToken())) builder.setOAuthAccessToken(mp.getOauthAccessToken()); if (!isEmpty(mp.getOauthAccessTokenSecret())) builder.setOAuthAccessTokenSecret(mp.getOauthAccessTokenSecret()); if (!isEmpty(mp.getAuthenUsername())) builder.setUser(mp.getAuthenUsername()); if (!isEmpty(mp.getAuthenPassword())) builder.setPassword(mp.getAuthenPassword()); return new TwitterFactory(builder.build()).getInstance(); }
From source file:org.primeoservices.cfgateway.twitter.railo.RailoTwitterUserStreamGateway.java
License:Apache License
/** * Initializes this gateway/*from ww w . j a va 2 s .c om*/ */ @Override @SuppressWarnings("rawtypes") public void init(final GatewayEngine engine, final String id, final String cfcPath, final Map config) throws IOException { try { this.argType = ArgumentType.fromConfigValue((String) config.get(ARGUMENT_TYPE)); final ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey((String) config.get(OAUTH_CONSUMER_KEY)); cb.setOAuthConsumerSecret((String) config.get(OAUTH_CONSUMER_SECRET)); cb.setOAuthAccessToken((String) config.get(OAUTH_ACCESS_TOKEN)); cb.setOAuthAccessTokenSecret((String) config.get(OAUTH_ACCESS_SECRET)); cb.setUserStreamRepliesAllEnabled(Boolean.valueOf((String) config.get(ALL_REPLIES))); cb.setJSONStoreEnabled(ArgumentType.JSON.equals(this.argType)); super.init(engine, id, new TwitterUserStream(this, cb.build())); } catch (Throwable t) { final IOException ex = new IOException("Unable to initialize gateway", t); this.onException(ex); throw ex; } }
From source file:org.smarttechie.servlet.SimpleStream.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String keywords = request.getParameter("keywords"); SEARCH_NAME = request.getParameter("SearchName"); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);/*ww w . j a va 2s. c o m*/ cb.setOAuthConsumerKey("Y8NvcZqWjUvNR0wfict2rSKmx"); cb.setOAuthConsumerSecret("A3K8YqVjLpTN5sSbk9MJ8DmiwIxRapLmyhmZcCau55sqzPjA1y"); cb.setOAuthAccessToken("566064066-BMF8JBt2JI7c4KBWEDtxRqPN2rLNxwKcUoykzoTR"); cb.setOAuthAccessTokenSecret("wo4LnwlsYYfbYkGixN0CS3NxlYfXxbxwl0gWfpQTIKas4"); //PrintStream out = new PrintStream(new FileOutputStream("/home/mary/Documents/Tesis/output.txt")); //System.setOut(out); Cluster cluster; Session session; cluster = Cluster.builder().addContactPoint("localhost").build(); session = cluster.connect("GetTheLead"); String[] parametros = { keywords }; twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); //EmbeddedNeo4j neo = new EmbeddedNeo4j(); //neo.createDb(); //neo.removeData(); //neo.shutDown(); graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb); getStream(twitterStream, parametros, session);//,out); //out.close(); }
From source file:org.talend.spark.operation.TwitterLoad.java
License:Open Source License
public static JavaDStream<List<Object>> twitterStream(JavaStreamingContext ctx, String username, String password, String accessToken, String secretToken, String[] filters, List<TwitterParameter> twitterParameters) { twitter4j.conf.ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthAccessToken(accessToken); builder.setOAuthAccessTokenSecret(secretToken); builder.setOAuthConsumerKey(username); builder.setOAuthConsumerSecret(password); JavaDStream<Status> inputDStream = null; if (filters.length > 0) { if (filters.length == 1 && filters[0].equals("")) inputDStream = TwitterUtils.createStream(ctx, new OAuthAuthorization(builder.build())); else/*from w ww . j a va2s .c om*/ inputDStream = TwitterUtils.createStream(ctx, new OAuthAuthorization(builder.build()), filters); return inputDStream.map(new LoadTwitterFunction(twitterParameters)); } return null; }
From source file:org.threeriverdev.twitterreporter.TwitterBot.java
License:Apache License
public static void main(String... args) throws Exception { FilterQuery query = new FilterQuery(); List<double[]> locations = new ArrayList<double[]>(); // Create a grid over the continental US. // TODO: Originally (2009ish), these were recommended by Twitter. Not sure if it's relevant now or not -- // could we achieve the same results with 1 big block? for (double swLat = 25.0; swLat <= 49.0; swLat = swLat + GRIDSIZE) { for (double swLon = -125.0; swLon <= -67.0; swLon = swLon + GRIDSIZE) { double neLat = swLat + GRIDSIZE; double neLon = swLon + GRIDSIZE; double[] swLocation = new double[2]; swLocation[0] = swLon;//from w ww . j av a 2s . c o m swLocation[1] = swLat; locations.add(swLocation); double[] neLocation = new double[2]; neLocation[0] = neLon; neLocation[1] = neLat; locations.add(neLocation); } } query.locations(locations.toArray(new double[0][0])); try { URL url = TwitterBot.class.getResource("/oauth.properties"); Properties p = new Properties(); InputStream inStream = url.openStream(); p.load(inStream); ConfigurationBuilder confBuilder = new ConfigurationBuilder(); confBuilder.setOAuthConsumerKey(p.getProperty("consumer.key")); confBuilder.setOAuthConsumerSecret(p.getProperty("consumer.secret")); confBuilder.setOAuthAccessToken(p.getProperty("access.token")); confBuilder.setOAuthAccessTokenSecret(p.getProperty("access.token.secret")); Configuration conf = confBuilder.build(); TwitterStream twitterStream = new TwitterStreamFactory(conf).getInstance(); twitterStream.addListener(new TweetProcessor()); twitterStream.filter(query); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.twitter.sample.main.Stream.java
public void getTweetsFromTwitter() { StatusListener listener = new StatusListener() { private boolean logQueueFull = true; @Override/*from w w w. j a va 2s. co m*/ public void onException(Exception e) { log.error(e); } @Override public void onDeletionNotice(StatusDeletionNotice notice) { } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onStatus(Status status) { db.insert(status); } @Override public void onTrackLimitationNotice(int notice) { log.warn("*** TRACK LIMITATION REACHED: " + notice + " ***"); } @Override public void onStallWarning(StallWarning arg0) { log.warn("*** STALL WARNING: " + arg0); } }; ConfigurationBuilder twitterConfig = new ConfigurationBuilder(); twitterConfig.setDebugEnabled(false); twitterConfig.setOAuthAccessTokenSecret(access_token_secret); twitterConfig.setOAuthAccessToken(access_token); twitterConfig.setOAuthConsumerKey(consumer_key); twitterConfig.setOAuthConsumerSecret(consumer_secret); twitterConfig.setJSONStoreEnabled(true); TwitterStreamFactory fact = new TwitterStreamFactory(twitterConfig.build()); this.twitterStream = fact.getInstance(); this.twitterStream.addListener(listener); FilterQuery filterQuery = new FilterQuery(); filterQuery.language(new String[] { "en" }); this.twitterStream.filter(filterQuery); this.twitterStream.sample(); }
From source file:org.vsepml.storm.twitter.StormTwitterStreamSpout.java
License:Apache License
@Override public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) { this.collector = spoutOutputCollector; queue = new LinkedBlockingQueue<Status>(1000); StatusListener listener = new StatusListener() { public void onStatus(Status status) { queue.offer(status);//from w w w.j av a 2 s. c om } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { } @Override public void onScrubGeo(long l, long l1) { } @Override public void onStallWarning(StallWarning stallWarning) { } public void onException(Exception ex) { ex.printStackTrace(); } }; ConfigurationBuilder twitterConf = new ConfigurationBuilder(); twitterConf.setIncludeEntitiesEnabled(true); twitterConf.setUseSSL(true); twitterConf.setUserStreamRepliesAllEnabled(true); twitterConf.setOAuthAccessToken(accessToken); twitterConf.setOAuthAccessTokenSecret(accessTokenSecret); twitterConf.setOAuthConsumerKey(consumerKey); twitterConf.setOAuthConsumerSecret(consumerSecret); twitterStream = new TwitterStreamFactory(twitterConf.build()).getInstance(); twitterStream.addListener(listener); // sample() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously. twitterStream.sample(); }
From source file:org.wso2.carbon.connector.twitter.TwitterClientLoader.java
License:Open Source License
public Twitter loadApiClient() throws TwitterException { Twitter twitter;//from ww w. j ava 2 s . c om if (messageContext.getProperty(TwitterConnectConstants.TWITTER_USER_CONSUMER_KEY) != null && messageContext.getProperty(TwitterConnectConstants.TWITTER_USER_CONSUMER_SECRET) != null && messageContext.getProperty(TwitterConnectConstants.TWITTER_USER_ACCESS_TOKEN) != null && messageContext.getProperty(TwitterConnectConstants.TWITTER_USER_ACCESS_TOKEN_SECRET) != null) { ConfigurationBuilder build = new ConfigurationBuilder(); build.setJSONStoreEnabled(true); build.setOAuthAccessToken( messageContext.getProperty(TwitterConnectConstants.TWITTER_USER_ACCESS_TOKEN).toString()); build.setOAuthAccessTokenSecret(messageContext .getProperty(TwitterConnectConstants.TWITTER_USER_ACCESS_TOKEN_SECRET).toString()); build.setOAuthConsumerKey( messageContext.getProperty(TwitterConnectConstants.TWITTER_USER_CONSUMER_KEY).toString()); build.setOAuthConsumerSecret( messageContext.getProperty(TwitterConnectConstants.TWITTER_USER_CONSUMER_SECRET).toString()); twitter = new TwitterFactory(build.build()).getInstance(); twitter.verifyCredentials(); } else { twitter = new TwitterFactory().getInstance(); } return twitter; }
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);/* w w 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"); 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); }