本文整理汇总了Java中com.twitter.hbc.core.endpoint.StatusesFilterEndpoint.followings方法的典型用法代码示例。如果您正苦于以下问题:Java StatusesFilterEndpoint.followings方法的具体用法?Java StatusesFilterEndpoint.followings怎么用?Java StatusesFilterEndpoint.followings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.twitter.hbc.core.endpoint.StatusesFilterEndpoint
的用法示例。
在下文中一共展示了StatusesFilterEndpoint.followings方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupHosebirdClient
import com.twitter.hbc.core.endpoint.StatusesFilterEndpoint; //导入方法依赖的package包/类
public static void setupHosebirdClient() {
/** Declare the host you want to connect to, the endpoint, and authentication (basic auth or oauth) */
Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST);
StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
// Optional: set up some followings and track terms
List<Long> followings = Lists.newArrayList(1234L, 566788L);
List<String> terms = Lists.newArrayList("twitter", "api");
endpoint.followings(followings);
endpoint.trackTerms(terms);
Authentication hosebirdAuth = new OAuth1(
Helper.properties().getProperty("consumerKey"),
Helper.properties().getProperty("consumerSecret"),
Helper.properties().getProperty("token"),
Helper.properties().getProperty("secret"));
ClientBuilder builder = new ClientBuilder()
.name("Hosebird-Client-01") // optional: mainly for the logs
.hosts(hosebirdHosts)
.authentication(hosebirdAuth)
.endpoint(endpoint)
.processor(new StringDelimitedProcessor(msgQueue));
hosebirdClient = builder.build();
}
示例2: TwitterClient
import com.twitter.hbc.core.endpoint.StatusesFilterEndpoint; //导入方法依赖的package包/类
public TwitterClient() {
/** Set up your blocking queues: Be sure to size these properly based on expected TPS of your stream */
BlockingQueue<String> msgQueue = new LinkedBlockingQueue<String>(100000);
BlockingQueue<Event> eventQueue = new LinkedBlockingQueue<Event>(1000);
/** 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();
// Optional: set up some followings and track terms
List<Long> followings = Lists.newArrayList(1234L, 566788L);
List<String> terms = Lists.newArrayList("twitter", "api");
hosebirdEndpoint.followings(followings);
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(new StatusesSampleEndpoint())
.processor(new StringDelimitedProcessor(msgQueue))
.eventMessageQueue(eventQueue); // optional: use this if you want to process client events
Client hosebirdClient = builder.build();
// Attempts to establish a connection.
hosebirdClient.connect();
}
示例3: getHosebirdClient
import com.twitter.hbc.core.endpoint.StatusesFilterEndpoint; //导入方法依赖的package包/类
/**
* Gets the Twitter client.
* @param buffer the queue which the client reads into
* @param readerConfig the Twitter reader configuration
* @return the built Twitter client
*/
@SuppressWarnings("checkstyle:designforextension")
@Override
protected Client getHosebirdClient(
final LinkedBlockingQueue<String> buffer,
final Config readerConfig) {
getLogger().info("Building Twitter client");
StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
TwitterApiConfig config = ((TwitterApiReaderConfig) readerConfig).twitterapi;
// Term tracking
if (config.keywords != null) {
endpoint.trackTerms(config.keywords);
}
// User ID tracking
if (config.userIds != null) {
endpoint.followings(config.userIds);
}
// Authentication
Authentication auth = new OAuth1(
config.consumerKey,
config.consumerSecret,
config.accessToken,
config.accessSecret
);
// Processor
LineStringProcessor processor =
new LineStringProcessor(buffer, readerConfig.hosebird.bufferTimeout);
// Create a new BasicClient. By default gzip is enabled.
return this.getClientBuilder()
.name("Twitter Api Reader")
.hosts(Constants.STREAM_HOST)
.endpoint(endpoint)
.authentication(auth)
.retries(readerConfig.hosebird.retries)
.processor(processor)
.build();
}
示例4: start
import com.twitter.hbc.core.endpoint.StatusesFilterEndpoint; //导入方法依赖的package包/类
@Start
public void start() {
queue = new LinkedBlockingQueue<>(100000);
BlockingQueue<Event> eventQueue = new LinkedBlockingQueue<>(1000);
// 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();
// set up some track terms
if (trackTerms != null && !trackTerms.isEmpty()) {
hosebirdEndpoint.trackTerms(Lists.newArrayList(trackTerms.split(" ")));
}
// set up some followings
if (followingIDs != null && !followingIDs.isEmpty()) {
Set<Long> followings = new HashSet<>();
for (String id: followingIDs.split(" ")) {
followings.add(Long.parseLong(id));
}
hosebirdEndpoint.followings(Lists.newArrayList(followings));
}
// These secrets should be read from a config file
Authentication hosebirdAuth = new OAuth1(consumerKey, consumerSecret, token, secret);
ClientBuilder builder = new ClientBuilder()
.name("twitter-client")
.hosts(hosebirdHosts)
.authentication(hosebirdAuth)
.endpoint(hosebirdEndpoint)
.processor(new StringDelimitedProcessor(queue))
.eventMessageQueue(eventQueue);
client = builder.build();
// Attempts to establish a connection.
client.connect();
executor.submit(() -> {
while (client != null && !client.isDone()) {
try {
String msg = queue.poll(5000, TimeUnit.MILLISECONDS);
if (msg != null) {
out.send(msg, null);
}
} catch (InterruptedException e) {
Log.warn("Twitter messages blocking queue interrupted while waiting.");
}
}
});
}
示例5: run
import com.twitter.hbc.core.endpoint.StatusesFilterEndpoint; //导入方法依赖的package包/类
@Override
public void run() {
// Create the authentication object
Authentication auth = new OAuth1(twitterConfig.getOAuthConsumerKey(), twitterConfig.getOAuthConsumerSecret(),
twitterConfig.getOAuthAccessToken(), twitterConfig.getOAuthAccessTokenSecret());
// Define the endpoint
StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
endpoint.followings(partyListHandler.getAllPartyMemberIds());
// Create the client
BasicClient client = new ClientBuilder().hosts(Constants.STREAM_HOST)
.endpoint(endpoint).authentication(auth)
.processor(new StringDelimitedProcessor(queue))
.build();
// Create the listeners
List<StatusListener> listeners = new ArrayList<>(indexConfig.getNumListeners());
for (int i = 0; i < indexConfig.getNumListeners(); i ++) {
listeners.add(new UKMPStatusStreamHandler("Handler" + i, searchEngine, partyListHandler));
}
int numProcessingThreads = indexConfig.getNumThreads();
ExecutorService service = Executors.newFixedThreadPool(numProcessingThreads);
// Wrap the basic client with the Twitter4j client
Twitter4jStatusClient t4jClient = new Twitter4jStatusClient(client, queue, listeners, service);
// Establish a connection
t4jClient.connect();
// Start the processor threads
for (int i = 0; i < numProcessingThreads; i ++) {
t4jClient.process();
}
running = true;
while (running) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
LOGGER.error("Sleep interrupted: {}", e.getMessage());
}
}
t4jClient.stop();
}