本文整理匯總了Java中twitter4j.conf.ConfigurationBuilder.setIncludeEntitiesEnabled方法的典型用法代碼示例。如果您正苦於以下問題:Java ConfigurationBuilder.setIncludeEntitiesEnabled方法的具體用法?Java ConfigurationBuilder.setIncludeEntitiesEnabled怎麽用?Java ConfigurationBuilder.setIncludeEntitiesEnabled使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twitter4j.conf.ConfigurationBuilder
的用法示例。
在下文中一共展示了ConfigurationBuilder.setIncludeEntitiesEnabled方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: twitterStream
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
@Bean
public TwitterStream twitterStream() {
String consumerKey = environment.getRequiredProperty("consumerKey");
String consumerSecret = environment.getRequiredProperty("consumerSecret");
String accessToken = environment.getRequiredProperty("accessToken");
String accessTokenSecret = environment.getRequiredProperty("accessTokenSecret");
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey(consumerKey);
cb.setOAuthConsumerSecret(consumerSecret);
cb.setOAuthAccessToken(accessToken);
cb.setOAuthAccessTokenSecret(accessTokenSecret);
cb.setJSONStoreEnabled(true);
cb.setIncludeEntitiesEnabled(true);
return new TwitterStreamFactory(cb.build()).getInstance();
}
示例2: configure
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
@Override
public void configure(Properties props) {
ProducerConfig config = new ProducerConfig(props);
producer = new Producer<String, String>(config);
// The necessary authentication keys to connect to twitter API v1.1
String consumerKey = props.getProperty(TwitterProducerConstants.CONSUMER_KEY_KEY);
String consumerSecret = props.getProperty(TwitterProducerConstants.CONSUMER_SECRET_KEY);
String accessToken = props.getProperty(TwitterProducerConstants.ACCESS_TOKEN_KEY);
String accessTokenSecret = props.getProperty(TwitterProducerConstants.ACCESS_TOKEN_SECRET_KEY);
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();
}
示例3: configure
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
/**
* 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.
*/
@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);
keywords = csvToArray(context.getString(TwitterSourceConstants.KEYWORDS_KEY, ""));
langs = csvToArray(context.getString(TwitterSourceConstants.LANGS_KEY, ""));
follow = csvToArrayLong(context.getString(TwitterSourceConstants.FOLLOWS_KEY, ""));
processLocations(context.getString(TwitterSourceConstants.LOCATIONS_KEY, ""));
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey(consumerKey);
cb.setOAuthConsumerSecret(consumerSecret);
cb.setOAuthAccessToken(accessToken);
cb.setOAuthAccessTokenSecret(accessTokenSecret);
cb.setJSONStoreEnabled(true); // important to convert status to raw json format
cb.setIncludeEntitiesEnabled(true);
twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
if (sourceCounter == null) {
sourceCounter = new TwitterSourceCounter(getName());
}
}
示例4: open
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
@Override
public final void open(final Map conf, final TopologyContext context,
final SpoutOutputCollector collector) {
this._queue = new LinkedBlockingQueue<>(1000);
this._outputCollector = collector;
final StatusListener statusListener = new StatusListener() {
@Override
public void onStatus(final Status status) {
_queue.offer(status);
}
@Override
public void onDeletionNotice(final StatusDeletionNotice sdn) {
}
@Override
public void onTrackLimitationNotice(final int i) {
}
@Override
public void onScrubGeo(final long l, final long l1) {
}
@Override
public void onStallWarning(final StallWarning stallWarning) {
}
@Override
public void onException(final Exception e) {
}
};
//Twitter stream authentication setup
final Properties properties = new Properties();
try {
properties.load(TwitterSpout.class.getClassLoader()
.getResourceAsStream(Constants.CONFIG_PROPERTIES_FILE));
} catch (final IOException ioException) {
//Should not occur. If it does, we cant continue. So exiting the program!
LOGGER.error(ioException.getMessage(), ioException);
System.exit(1);
}
final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setIncludeEntitiesEnabled(true);
configurationBuilder.setOAuthAccessToken(properties.getProperty(Constants.OAUTH_ACCESS_TOKEN));
configurationBuilder.setOAuthAccessTokenSecret(properties.getProperty(Constants.OAUTH_ACCESS_TOKEN_SECRET));
configurationBuilder.setOAuthConsumerKey(properties.getProperty(Constants.OAUTH_CONSUMER_KEY));
configurationBuilder.setOAuthConsumerSecret(properties.getProperty(Constants.OAUTH_CONSUMER_SECRET));
this._twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance();
this._twitterStream.addListener(statusListener);
//Our usecase computes the sentiments of States of USA based on tweets.
//So we will apply filter with US bounding box so that we get tweets specific to US only.
final FilterQuery filterQuery = new FilterQuery();
//Bounding Box for United States.
//For more info on how to get these coordinates, check:
//https://wiki.ceh.ac.uk/display/cehigh/Bounding+box
//-8.164723,49.955269,1.7425,60.6311
//-9.05, 48.77, 2.19, 58.88
final double[][] boundingBoxOfUK = {{-9.23, 49.84},
{2.69, 60.85}};
filterQuery.locations(boundingBoxOfUK);
this._twitterStream.filter(filterQuery);
}
示例5: open
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
@Override
public final void open(final Map conf, final TopologyContext context,
final SpoutOutputCollector collector) {
this._queue = new LinkedBlockingQueue<>(1000);
this._outputCollector = collector;
final StatusListener statusListener = new StatusListener() {
@Override
public void onStatus(final Status status) {
_queue.offer(status);
}
@Override
public void onDeletionNotice(final StatusDeletionNotice sdn) {
}
@Override
public void onTrackLimitationNotice(final int i) {
}
@Override
public void onScrubGeo(final long l, final long l1) {
}
@Override
public void onStallWarning(final StallWarning stallWarning) {
}
@Override
public void onException(final Exception e) {
}
};
//Twitter stream authentication setup
final Properties properties = new Properties();
try {
properties.load(TwitterSpout.class.getClassLoader()
.getResourceAsStream(Constants.CONFIG_PROPERTIES_FILE));
} catch (final IOException ioException) {
//Should not occur. If it does, we cant continue. So exiting the program!
LOGGER.error(ioException.getMessage(), ioException);
System.exit(1);
}
final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setIncludeEntitiesEnabled(true);
configurationBuilder.setOAuthAccessToken(properties.getProperty(Constants.OAUTH_ACCESS_TOKEN));
configurationBuilder.setOAuthAccessTokenSecret(properties.getProperty(Constants.OAUTH_ACCESS_TOKEN_SECRET));
configurationBuilder.setOAuthConsumerKey(properties.getProperty(Constants.OAUTH_CONSUMER_KEY));
configurationBuilder.setOAuthConsumerSecret(properties.getProperty(Constants.OAUTH_CONSUMER_SECRET));
this._twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance();
this._twitterStream.addListener(statusListener);
//Our usecase computes the sentiments of States of USA based on tweets.
//So we will apply filter with US bounding box so that we get tweets specific to US only.
final FilterQuery filterQuery = new FilterQuery();
//Bounding Box for United States.
//For more info on how to get these coordinates, check:
//http://www.quora.com/Geography/What-is-the-longitude-and-latitude-of-a-bounding-box-around-the-continental-United-States
final double[][] boundingBoxOfUS = {{-124.848974, 24.396308},
{-66.885444, 49.384358}};
filterQuery.locations(boundingBoxOfUS);
this._twitterStream.filter(filterQuery);
}
示例6: open
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
@Override
public void open(Map confMap, TopologyContext context,
SpoutOutputCollector collector) {
_collector = collector;
queue = new LinkedBlockingQueue<Status>(1000);
//implement a listener for twitter statuses
StatusListener listener = new StatusListener(){
public void onStatus(Status status) {
queue.offer(status);
}
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {}
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {}
public void onException(Exception ex) {
ex.printStackTrace();
}
@Override
public void onScrubGeo(long userId, long upToStatusId) {
}
@Override
public void onStallWarning(StallWarning warning) {
}
};
//twitter stream authentication setup
Properties prop = new Properties();
try {
prop.load(TwitterSpout.class.getClassLoader().getResourceAsStream("config.properties"));
} catch (IOException e) {
log.error(e.toString());
}
ConfigurationBuilder twitterConf = new ConfigurationBuilder();
twitterConf.setIncludeEntitiesEnabled(true);
twitterConf.setOAuthAccessToken(prop.getProperty("OATH_ACCESS_TOKEN"));
twitterConf.setOAuthAccessTokenSecret(prop.getProperty("OATH_ACCESS_TOKEN_SECRET"));
twitterConf.setOAuthConsumerKey(prop.getProperty("OATH_CONSUMER_KEY"));
twitterConf.setOAuthConsumerSecret(prop.getProperty("OATH_CONSUMER_SECRET"));
TwitterStream twitterStream = new TwitterStreamFactory(twitterConf.build()).getInstance();
twitterStream.addListener(listener);
// sample() method internally creates a thread which manipulates TwitterStream and calls
//the listener methods continuously.
twitterStream.sample();
}
示例7: open
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
@Override
public final void open(final Map conf, final TopologyContext context,
final SpoutOutputCollector collector) {
this._queue = new LinkedBlockingQueue<>(1000);
this._collector = collector;
final StatusListener statusListener = new StatusListener() {
@Override
public void onStatus(final Status status) {
_queue.offer(status);
}
@Override
public void onDeletionNotice(final StatusDeletionNotice sdn) {
//No-op
}
@Override
public void onTrackLimitationNotice(final int i) {
//No-op
}
@Override
public void onScrubGeo(final long l, final long l1) {
//No-op
}
@Override
public void onStallWarning(final StallWarning stallWarning) {
//No-op
}
@Override
public void onException(final Exception e) {
//No-op
}
};
//Twitter stream authentication setup
final Properties properties = new Properties();
try {
properties.load(TwitterSpout.class.getClassLoader()
.getResourceAsStream(Constants.CONFIG_PROPERTIES_FILE));
} catch (final IOException exception) {
//Should not occur. If it does, we cant continue. So exiting the program!
LOGGER.error(exception.toString());
System.exit(1);
}
final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setIncludeEntitiesEnabled(true);
configurationBuilder.setOAuthAccessToken(properties.getProperty(Constants.OAUTH_ACCESS_TOKEN));
configurationBuilder.setOAuthAccessTokenSecret(properties.getProperty(Constants.OAUTH_ACCESS_TOKEN_SECRET));
configurationBuilder.setOAuthConsumerKey(properties.getProperty(Constants.OAUTH_CONSUMER_KEY));
configurationBuilder.setOAuthConsumerSecret(properties.getProperty(Constants.OAUTH_CONSUMER_SECRET));
this._twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance();
this._twitterStream.addListener(statusListener);
//Returns a small random sample of all public statuses.
this._twitterStream.sample();
}