endpoint = new StatusesFilterEndpoint();
final StatusesFilterEndpoint filterEndpoint = new StatusesFilterEndpoint();
public static void run(String consumerKey, String consumerSecret, String token, String secret) throws InterruptedException { BlockingQueue<String> queue = new LinkedBlockingQueue<String>(10000); StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint(); // add some track terms endpoint.trackTerms(Lists.newArrayList("twitterapi", "#yolo")); Authentication auth = new OAuth1(consumerKey, consumerSecret, token, secret); // Authentication auth = new BasicAuth(username, password); // Create a new BasicClient. By default gzip is enabled. Client client = new ClientBuilder() .hosts(Constants.STREAM_HOST) .endpoint(endpoint) .authentication(auth) .processor(new StringDelimitedProcessor(queue)) .build(); // Establish a connection client.connect(); // Do whatever needs to be done with messages for (int msgRead = 0; msgRead < 1000; msgRead++) { String msg = queue.take(); System.out.println(msg); } client.stop(); }
private Client getTwitterClient(Properties props, BlockingQueue<String> messageQueue) { String clientName = props.getProperty("clientName"); String consumerKey = props.getProperty("consumerKey"); String consumerSecret = props.getProperty("consumerSecret"); String token = props.getProperty("token"); String tokenSecret = props.getProperty("tokenSecret"); List<String> searchTerms = Arrays.asList(props.getProperty("searchTerms").split(",")); Authentication authentication = new OAuth1(consumerKey,consumerSecret,token,tokenSecret); Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST); StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint(); hosebirdEndpoint.trackTerms(searchTerms); ClientBuilder clientBuilder = new ClientBuilder(); clientBuilder.name(clientName) .hosts(hosebirdHosts) .authentication(authentication) .endpoint(hosebirdEndpoint) .processor(new StringDelimitedProcessor(messageQueue)); return clientBuilder.build(); }
StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint();
StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
public TwitterConnector(List<String> keywordList, List<Location> locationList, List<String> languageList, String customerKey, String customerSecret, String token, String tokenSecret) throws TexeraException { if ((keywordList == null || keywordList.isEmpty()) && (locationList == null || locationList.isEmpty()) && (languageList == null || languageList.isEmpty())) { throw new DataflowException("no filter is provided"); } //Set up the blocking queue with proper size based on expected TPS of the stream. messageQueue = new LinkedBlockingQueue<String>(queueSize); StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint(); if (!(keywordList == null || keywordList.isEmpty())) { endpoint.trackTerms(keywordList); } if (!(locationList == null || locationList.isEmpty())) { endpoint.locations(locationList); } if (!(languageList == null || languageList.isEmpty())) { endpoint.languages(languageList); } if ((customerKey != null && !customerKey.isEmpty()) && (customerSecret != null && !customerSecret.isEmpty()) && (token != null && !token.isEmpty()) && (tokenSecret != null && !tokenSecret.isEmpty())) { auth = new OAuth1(customerKey, customerSecret, token, tokenSecret); } else { auth = new OAuth1(TwitterUtils.twitterConstant.consumerKey, TwitterUtils.twitterConstant.consumerSecret, TwitterUtils.twitterConstant.token, TwitterUtils.twitterConstant.tokenSecret); } //BasicClient sets up connection to twitter with declaration on hostname to connect to, endpoint with trackTerms, authentication information and processor to process client events. twitterClient = new ClientBuilder() .hosts(Constants.STREAM_HOST) .endpoint(endpoint) .authentication(auth) .processor(new StringDelimitedProcessor(messageQueue)) .build(); }
@PostConstruct public void init() { BlockingQueue<String> queue = new LinkedBlockingQueue<>(100); StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint(); endpoint.trackTerms(ImmutableList.of("ExtJS", "#extjs", "Sencha", "#java", "java8", "java9", "#websocket", "#SpringFramework", "html5", "javascript", "#kotlin", "kotlin")); endpoint.languages(ImmutableList.of("en", "de")); String consumerKey = this.environment.getProperty("twitter4j.oauth.consumerKey"); String consumerSecret = this.environment .getProperty("twitter4j.oauth.consumerSecret"); String accessToken = this.environment.getProperty("twitter4j.oauth.accessToken"); String accessTokenSecret = this.environment .getProperty("twitter4j.oauth.accessTokenSecret"); Authentication auth = new OAuth1(consumerKey, consumerSecret, accessToken, accessTokenSecret); this.client = new ClientBuilder().hosts(Constants.STREAM_HOST).endpoint(endpoint) .authentication(auth).processor(new StringDelimitedProcessor(queue)) .build(); this.executorService = Executors.newSingleThreadExecutor(); TwitterStatusListener statusListener = new TwitterStatusListener( this.messagingTemplate, this.lastTweets); this.t4jClient = new Twitter4jStatusClient(this.client, queue, ImmutableList.of(statusListener), this.executorService); this.t4jClient.connect(); this.t4jClient.process(); }
StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
@Override protected void init(@Nonnull Context context) { StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint(); endpoint.trackTerms(terms); String consumerKey = properties.getProperty("consumerKey"); String consumerSecret = properties.getProperty("consumerSecret"); String token = properties.getProperty("token"); String tokenSecret = properties.getProperty("tokenSecret"); if (isMissing(consumerKey) || isMissing(consumerSecret) || isMissing(token) || isMissing(tokenSecret)) { throw new IllegalArgumentException("Twitter credentials are missing!"); } Authentication auth = new OAuth1(consumerKey, consumerSecret, token, tokenSecret); client = new ClientBuilder() .hosts(Constants.STREAM_HOST) .endpoint(endpoint) .authentication(auth) .processor(new StringDelimitedProcessor(queue)) .build(); client.connect(); }
TwitterSource(Properties properties, List<String> terms) { StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint().trackTerms(terms); String consumerKey = properties.getProperty("consumerKey"); String consumerSecret = properties.getProperty("consumerSecret"); String token = properties.getProperty("token"); String tokenSecret = properties.getProperty("tokenSecret"); if (isMissing(consumerKey) || isMissing(consumerSecret) || isMissing(token) || isMissing(tokenSecret)) { throw new IllegalArgumentException("Twitter credentials are missing!"); } Authentication auth = new OAuth1(consumerKey, consumerSecret, token, tokenSecret); client = new ClientBuilder() .hosts(Constants.STREAM_HOST) .endpoint(endpoint) .authentication(auth) .processor(new StringDelimitedProcessor(queue)) .build(); client.connect(); }
StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint(); List<String> terms = Lists.newArrayList("superman vs batman","#supermanvsbatman"); hosebirdEndpoint.trackTerms(terms);
final StatusesFilterEndpoint filterEndpoint = new StatusesFilterEndpoint();
public Client createTwitterClient(BlockingQueue<String> msgQueue){ /** Declare the host you want to connect to, the endpoint, and authentication (basic auth or oauth) */ Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST); StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint(); hosebirdEndpoint.trackTerms(terms); // These secrets should be read from a config file Authentication hosebirdAuth = new OAuth1(consumerKey, consumerSecret, token, secret); ClientBuilder builder = new ClientBuilder() .name("Hosebird-Client-01") // optional: mainly for the logs .hosts(hosebirdHosts) .authentication(hosebirdAuth) .endpoint(hosebirdEndpoint) .processor(new StringDelimitedProcessor(msgQueue)); Client hosebirdClient = builder.build(); return hosebirdClient; }