List of usage examples for twitter4j TwitterStreamFactory TwitterStreamFactory
public TwitterStreamFactory(String configTreePath)
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. *///from w w w . j a v a 2s. c o m @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.opencredo.twitter.si.TwitterStreamInboundChannelAdapter.java
License:Apache License
protected TwitterStreamFactory getTwitterStreamFactory() { return new TwitterStreamFactory(this); }
From source file:org.primeoservices.cfgateway.twitter.AbstractTwitterStream.java
License:Apache License
/** * Starts this stream /*from w w w . jav a2 s. co m*/ */ @Override public void startStream() { this.stream = new TwitterStreamFactory(this.configuration).getInstance(); this.initStream(this.stream); }
From source file:org.rtsa.storm.TwitterSpout.java
License:Apache License
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { queue = new LinkedBlockingQueue<Status>(1000); _collector = collector;//from w ww . j ava2 s . c om StatusListener listener = new StatusListener() { public void onStatus(Status status) { if (status.getText().length() != 0 && status.getLang().equals("en")) { queue.offer(status); } } public void onDeletionNotice(StatusDeletionNotice sdn) { } public void onTrackLimitationNotice(int i) { } public void onScrubGeo(long l, long l1) { } public void onException(Exception ex) { } public void onStallWarning(StallWarning arg0) { // TODO Auto-generated method stub } }; TwitterStream twitterStream = new TwitterStreamFactory( new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance(); twitterStream.addListener(listener); twitterStream.setOAuthConsumer(consumerKey, consumerSecret); AccessToken token = new AccessToken(accessToken, accessTokenSecret); twitterStream.setOAuthAccessToken(token); if (keyWords.length == 0) { twitterStream.sample(); } else { FilterQuery query = new FilterQuery().track(keyWords); twitterStream.filter(query); } }
From source file:org.selman.tweetamo.TweetamoClient.java
License:Apache License
public static void main(String[] args) throws Exception { if (args.length != 2) { System.out.println("Usage: [language] [search topic]"); }/*from w w w. j ava 2 s . com*/ kinesisClient = new AmazonKinesisClient(new ClasspathPropertiesFileCredentialsProvider()); waitForStreamToBecomeAvailable(STREAM_NAME); LOG.info("Publishing tweets to stream : " + STREAM_NAME); StatusListener listener = new StatusListener() { public void onStatus(Status status) { try { PutRecordRequest putRecordRequest = new PutRecordRequest(); putRecordRequest.setStreamName(STREAM_NAME); putRecordRequest.setData(TweetSerializer.toBytes(status)); putRecordRequest.setPartitionKey(status.getUser().getScreenName()); PutRecordResult putRecordResult = kinesisClient.putRecord(putRecordRequest); LOG.info("Successfully putrecord, partition key : " + putRecordRequest.getPartitionKey() + ", ShardID : " + putRecordResult.getShardId()); } catch (Exception e) { LOG.error("Failed to putrecord", e); } } public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { } public void onTrackLimitationNotice(int numberOfLimitedStatuses) { } public void onException(Exception ex) { ex.printStackTrace(); } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onStallWarning(StallWarning arg0) { } }; ClasspathTwitterCredentialsProvider provider = new ClasspathTwitterCredentialsProvider(); TwitterCredentials credentials = provider.getTwitterCredentials(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(credentials.getConsumerKey()) .setOAuthConsumerSecret(credentials.getConsumerSecret()) .setOAuthAccessToken(credentials.getAccessToken()) .setOAuthAccessTokenSecret(credentials.getAccessTokenSecret()); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); twitterStream.addListener(listener); FilterQuery filterQuery = new FilterQuery(); filterQuery.language(new String[] { args[0] }); filterQuery.track(new String[] { args[1] }); twitterStream.filter(filterQuery); }
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 av a2 s. com*/ 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.sush.twitterstream.MyTwitterStream.java
License:Apache License
public void init() throws IOException { configurationBuilder = new ConfigurationBuilder(); String configDIr = System.getenv("SUSH_JAVA_CONFIG"); File file = new File("E:\\java_config\\twitter4j.properties"); Properties properties = new Properties(); if (file.exists()) { InputStream fileInputStream = new FileInputStream(file); properties.load(fileInputStream); } else {/*from ww w.j a va 2s . c om*/ System.out.println("Property file not found... Program Exiting"); System.exit(-1); } String oAuthConsumerKey = properties.getProperty("oauth.consumerSecret", ""); String oAuthConsumerSecret = properties.getProperty("oauth.consumerKey", ""); configurationBuilder.setOAuthConsumerKey(oAuthConsumerKey); configurationBuilder.setOAuthConsumerSecret(oAuthConsumerSecret); twitterException = null; twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance(); statusListener = new MyTwitterStatusListener(this); connectionListener = new MyTwitterConnectionLifeCycleListener(this); twitterStream.addListener(statusListener); twitterStream.addConnectionLifeCycleListener(connectionListener); }
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 www . j av a 2 s . c om*/ 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 www .ja va 2 s. com 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.umd.assignment.spout.TwitterSampleSpout.java
License:Apache License
@Override public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { queue = new LinkedBlockingQueue<String>(1000); _collector = collector;// ww w. j a va 2 s .com StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { queue.offer(status.getText()); } @Override public void onDeletionNotice(StatusDeletionNotice sdn) { } @Override public void onTrackLimitationNotice(int i) { } @Override public void onScrubGeo(long l, long l1) { } @Override public void onException(Exception ex) { } @Override public void onStallWarning(StallWarning arg0) { } }; TwitterStreamFactory fact = new TwitterStreamFactory( new ConfigurationBuilder().setJSONStoreEnabled(true).build()); _twitterStream = fact.getInstance(); _twitterStream.addListener(listener); _twitterStream.setOAuthConsumer(consumerKey, consumerSecret); AccessToken token = new AccessToken(accessToken, accessTokenSecret); _twitterStream.setOAuthAccessToken(token); if (keyWords.length == 0) { _twitterStream.sample(); } else { FilterQuery query = new FilterQuery().track(keyWords); _twitterStream.filter(query); } }