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

The following examples show how to use twitter4j.conf.ConfigurationBuilder#setDebugEnabled() . 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: NotificationResource.java    From sample-acmegifts with Eclipse Public License 1.0 5 votes vote down vote up
@PostConstruct
public void init() {
  try {
    File log = new File(logFile);
    File parentDir = log.getParentFile();
    if (!parentDir.exists()) {
      parentDir.mkdirs();
    }

    FileHandler fh = new FileHandler(logFile);
    logger.addHandler(fh);
    SimpleFormatter formatter = new SimpleFormatter();
    fh.setFormatter(formatter);

    File fbLog = new File(fallbackLogFile);
    File fbParentDir = fbLog.getParentFile();
    if (!fbParentDir.exists()) {
      fbParentDir.mkdirs();
    }

    FileHandler fbFh = new FileHandler(fallbackLogFile);
    fbLogger.addHandler(fbFh);
    SimpleFormatter fbFormatter = new SimpleFormatter();
    fbFh.setFormatter(fbFormatter);

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setTweetModeExtended(true);
    cb.setOAuthConsumerKey(consumerKey);
    cb.setOAuthConsumerSecret(consumeSecret);
    cb.setOAuthAccessToken(accessToken);
    cb.setOAuthAccessTokenSecret(acessSecret);
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();
  } catch (Exception e) {
    throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
  }
}
 
Example 2
Source File: TwitterReader.java    From swcv with MIT License 5 votes vote down vote up
public static Twitter getTwitterInstance()
{
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(false);
    cb.setOAuthConsumerKey(TwitterCredentials.CONSUMER_KEY);
    cb.setOAuthConsumerSecret(TwitterCredentials.CONSUMER_SECRET);
    cb.setOAuthAccessToken(TwitterCredentials.ACCESS_TOKEN);
    cb.setOAuthAccessTokenSecret(TwitterCredentials.ACCESS_TOKEN_SECRET);
    TwitterFactory tf = new TwitterFactory(cb.build());
    return tf.getInstance();
}
 
Example 3
Source File: TwitterApi.java    From SmileEssence with MIT License 5 votes vote down vote up
public static Configuration getConf(String consumerKey, String consumerSecret) {
    ConfigurationBuilder conf = new ConfigurationBuilder();
    conf.setOAuthConsumerKey(consumerKey);
    conf.setOAuthConsumerSecret(consumerSecret);
    conf.setDebugEnabled(true);
    return conf.build();
}
 
Example 4
Source File: TwitterOAuth.java    From TweetwallFX with MIT License 4 votes vote down vote up
private static Configuration createConfiguration() {
    final org.tweetwallfx.config.Configuration tweetWallFxConfig = org.tweetwallfx.config.Configuration.getInstance();
    final TwitterSettings twitterSettings = org.tweetwallfx.config.Configuration.getInstance()
            .getConfigTyped(TwitterSettings.CONFIG_KEY, TwitterSettings.class);

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setDebugEnabled(twitterSettings.isDebugEnabled());
    builder.setTweetModeExtended(twitterSettings.isExtendedMode());

    TwitterSettings.OAuth twitterOAuthSettings = twitterSettings.getOauth();
    builder.setOAuthConsumerKey(twitterOAuthSettings.getConsumerKey());
    builder.setOAuthConsumerSecret(twitterOAuthSettings.getConsumerSecret());
    builder.setOAuthAccessToken(twitterOAuthSettings.getAccessToken());
    builder.setOAuthAccessTokenSecret(twitterOAuthSettings.getAccessTokenSecret());

    // optional proxy settings
    tweetWallFxConfig.getConfigTypedOptional(ConnectionSettings.CONFIG_KEY, ConnectionSettings.class)
            .map(ConnectionSettings::getProxy)
            .filter(proxy -> Objects.nonNull(proxy.getHost()) && !proxy.getHost().isEmpty())
            .ifPresent(proxy -> {
                builder.setHttpProxyHost(proxy.getHost());
                builder.setHttpProxyPort(proxy.getPort());
                builder.setHttpProxyUser(proxy.getUser());
                builder.setHttpProxyPassword(proxy.getPassword());
            });

    Configuration conf = builder.build();

    // check Configuration
    if (conf.getOAuthConsumerKey() != null && !conf.getOAuthConsumerKey().isEmpty()
            && conf.getOAuthConsumerSecret() != null && !conf.getOAuthConsumerSecret().isEmpty()
            && conf.getOAuthAccessToken() != null && !conf.getOAuthAccessToken().isEmpty()
            && conf.getOAuthAccessTokenSecret() != null && !conf.getOAuthAccessTokenSecret().isEmpty()) {
        Twitter twitter = new TwitterFactory(conf).getInstance();
        try {
            User user = twitter.verifyCredentials();
            LOGGER.info("User " + user.getName() + " validated");
        } catch (TwitterException ex) {
            EXCEPTION.set(ex);
            //  statusCode=400, message=Bad Authentication data -> wrong token
            //  statusCode=401, message=Could not authenticate you ->wrong consumerkey
            int statusCode = ex.getStatusCode();
            LOGGER.error("Error statusCode=" + statusCode + " " + (statusCode > 0 ? ex.getErrorMessage() : ex.getMessage()));
            conf = null;
        }
    } else {
        EXCEPTION.set(new IllegalStateException("Missing credentials!"));
    }

    return conf;
}
 
Example 5
Source File: TwitterSampleChannel.java    From realtime-analytics with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void open() throws EventException {
    super.open();
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(false);

    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    StatusListener listener = new StatusListener() {
        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        @Override
        public void onException(Exception ex) {
            ex.printStackTrace();
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
        }

        @Override
        public void onStallWarning(StallWarning warning) {
        }

        @Override
        public void onStatus(Status status) {
            HashtagEntity[] hashtagEntities = status.getHashtagEntities();
            
            JetstreamEvent event = new JetstreamEvent();
            event.setEventType("TwitterSample");

            Place place = status.getPlace();
            if (place != null) {
                event.put("country", place.getCountry());
            }
            event.put("ct", status.getCreatedAt().getTime());
            event.put("text", status.getText());
            event.put("lang", status.getLang());
            event.put("user", status.getUser().getName());
            if (hashtagEntities != null && hashtagEntities.length > 0) {
                StringBuilder s = new StringBuilder();
                s.append(hashtagEntities[0].getText());
                
                for (int i = 1; i < hashtagEntities.length; i++) {
                    s.append(",");
                    s.append(hashtagEntities[i].getText());
                }
                
                event.put("hashtag", s.toString());
            }

            fireSendEvent(event);
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }
    };
    twitterStream.addListener(listener);
    twitterStream.sample(); 
}
 
Example 6
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();

}