Java Code Examples for twitter4j.conf.ConfigurationBuilder#setJSONStoreEnabled()

The following examples show how to use twitter4j.conf.ConfigurationBuilder#setJSONStoreEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatasetFeaturesExtractor.java    From image-verification-corpus with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the connection to Twitter API.
 * @return Twitter object for the current connection
 */
public static Twitter connectToTwitterAPI() {

	ConfigurationBuilder cb = new ConfigurationBuilder();
	/*please fill in your credentials*/
	cb.setDebugEnabled(true).setOAuthConsumerKey("CONSUMER_KEY")
			.setOAuthConsumerSecret("CONSUMER_SECRET")
			.setOAuthAccessToken("ACCESS_TOKEN")
			.setOAuthAccessTokenSecret("ACCESS_TOKEN_SECRET");

	cb.setJSONStoreEnabled(true);

	TwitterFactory tf = new TwitterFactory(cb.build());
	Twitter twitter = tf.getInstance();

	return twitter;
}
 
Example 2
Source File: TwitterProducer.java    From lsiem with Apache License 2.0 4 votes vote down vote up
private void start(Context context) {

/** Producer properties **/
Properties props = new Properties();
props.put("metadata.broker.list", context.getString(TwitterSourceConstant.BROKER_LIST));
props.put("serializer.class", context.getString(TwitterSourceConstant.SERIALIZER));
props.put("request.required.acks", context.getString(TwitterSourceConstant.REQUIRED_ACKS));

ProducerConfig config = new ProducerConfig(props);

final Producer<String, String> producer = new Producer<String, String>(config);

/** Twitter properties **/
consumerKey = context.getString(TwitterSourceConstant.CONSUMER_KEY_KEY);
consumerSecret = context.getString(TwitterSourceConstant.CONSUMER_SECRET_KEY);
accessToken = context.getString(TwitterSourceConstant.ACCESS_TOKEN_KEY);
accessTokenSecret = context.getString(TwitterSourceConstant.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();
final Map<String, String> headers = new HashMap<String, String>();

/** Twitter listener **/
StatusListener listener = new StatusListener() {
	// The onStatus method is executed every time a new tweet comes
	// in.
	public void onStatus(Status status) {
	    // The EventBuilder is used to build an event using the
	    // the raw JSON of a tweet
	    logger.info(status.getUser().getScreenName() + ": " + status.getText()); //delete uncomment sign
	    
	    KeyedMessage<String, String> data = new KeyedMessage<String, String>(context.getString(TwitterSourceConstant.KAFKA_TOPIC)
										 , DataObjectFactory.getRawJSON(status));
	    producer.send(data);
	    
	}
	    
	public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {}
	
	public void onTrackLimitationNotice(int numberOfLimitedStatuses) {}
	
	public void onScrubGeo(long userId, long upToStatusId) {}
	
	public void onException(Exception ex) {
	    logger.info("Shutting down Twitter sample stream...");
	    //twitterStream.shutdown();
	}
	
	public void onStallWarning(StallWarning warning) {}
    };

/** Bind the listener **/
twitterStream.addListener(listener);
/** GOGOGO **/
twitterStream.sample();   
   }
 
Example 3
Source File: TwitterSource.java    From fiware-cygnus with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void configure(Context context) {
    consumerKey = context.getString("consumerKey");
    consumerSecret = context.getString("consumerSecret");
    accessToken = context.getString("accessToken");
    accessTokenSecret = context.getString("accessTokenSecret");

    LOGGER.info("Consumer Key:        '" + consumerKey + "'");
    LOGGER.info("Consumer Secret:     '" + consumerSecret + "'");
    LOGGER.info("Access Token:        '" + accessToken + "'");
    LOGGER.info("Access Token Secret: '" + accessTokenSecret + "'");

    String southWestLatitude;
    String southWestLongitude;
    String northEastLatitude;
    String northEastLongitude;
    String keywords;

    //Top-left coordinate
    southWestLatitude = context.getString("south_west_latitude");
    southWestLongitude = context.getString("south_west_longitude");
    LOGGER.info("South-West coordinate: '" + southWestLatitude + " " + southWestLongitude + "'");

    //Bottom-right coordinate
    northEastLatitude = context.getString("north_east_latitude");
    northEastLongitude = context.getString("north_east_longitude");
    LOGGER.info("North-East coordinate: '" + northEastLatitude + " " + northEastLongitude + "'");

    keywords = context.getString("keywords");
    LOGGER.info("Keywords:            '" + keywords + "'");

    if (southWestLatitude != null && southWestLongitude != null
            && northEastLatitude != null && northEastLongitude != null) {
        double latitude1 = Double.parseDouble(southWestLatitude);
        double longitude1 = Double.parseDouble(southWestLongitude);

        double latitude2 = Double.parseDouble(northEastLatitude);
        double longitude2 = Double.parseDouble(northEastLongitude);

        boundingBox = new double[][]{
            new double[]{longitude1, latitude1}, // south-west
            new double[]{longitude2, latitude2}  // north-east
        };

        LOGGER.info("Coordinates:         '" + boundingBox[0][0] + " " + boundingBox[0][1]
                + " " + boundingBox[1][0] + " " + boundingBox[1][1] + "'");
        haveFilters = true;
        haveCoordinateFilter = true;
    }

    if (keywords != null) {
        if (keywords.trim().length() != 0) {
            splitKeywords = keywords.split(",");
            for (int i = 0; i < splitKeywords.length; i++) {
                splitKeywords[i] = splitKeywords[i].trim();
            }

            LOGGER.info("keywords:            {}", Arrays.toString(splitKeywords));
            haveFilters = true;
            haveKeywordFilter = true;
        }
    }

    maxBatchSize = context.getInteger("maxBatchSize", maxBatchSize);
    maxBatchDurationMillis = context.getInteger("maxBatchDurationMillis",
            maxBatchDurationMillis);

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey(consumerKey);
    cb.setOAuthConsumerSecret(consumerSecret);
    cb.setOAuthAccessToken(accessToken);
    cb.setOAuthAccessTokenSecret(accessTokenSecret);
    cb.setJSONStoreEnabled(true);

    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();

}