Example usage for twitter4j.conf ConfigurationBuilder ConfigurationBuilder

List of usage examples for twitter4j.conf ConfigurationBuilder ConfigurationBuilder

Introduction

In this page you can find the example usage for twitter4j.conf ConfigurationBuilder ConfigurationBuilder.

Prototype

ConfigurationBuilder

Source Link

Usage

From source file:com.dwdesign.tweetings.util.Utils.java

License:Open Source License

public static HttpClientWrapper getHttpClient(final int timeout_millis, final boolean ignore_ssl_error,
        final Proxy proxy, final HostAddressResolver resolver, final String user_agent) {
    final ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setHttpConnectionTimeout(timeout_millis);
    if (proxy != null && !Proxy.NO_PROXY.equals(proxy)) {
        final SocketAddress address = proxy.address();
        if (address instanceof InetSocketAddress) {
            cb.setHttpProxyHost(((InetSocketAddress) address).getHostName());
            cb.setHttpProxyPort(((InetSocketAddress) address).getPort());
        }/*from   w w w.  jav  a 2 s  .c om*/
    }
    // cb.setHttpClientImplementation(HttpClientImpl.class);
    return new HttpClientWrapper(cb.build());
}

From source file:com.ebay.pulsar.twittersample.channel.TwitterSampleChannel.java

License:GNU General Public License

@Override
public void open() throws EventException {
    super.open();
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(false);/*from   ww  w.  jav  a2s  .  co m*/

    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();
}

From source file:com.esri.geoevent.transport.twitter.TwitterInboundTransport.java

License:Apache License

private void receiveData() {
    try {//from  www . ja  v  a  2 s.  c  om
        applyProperties();
        setRunningState(RunningState.STARTED);

        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true);
        cb.setOAuthConsumerKey(consumerKey);
        cb.setOAuthConsumerSecret(consumerSecret);
        cb.setOAuthAccessToken(accessToken);
        cb.setOAuthAccessTokenSecret(accessTokenSecret);
        twitterStream = new TwitterStreamFactory(cb.build()).getInstance();

        RawStreamListener rl = new RawStreamListener() {

            @Override
            public void onException(Exception ex) {
                LOGGER.error("INBOUND_TRANSPORT_RAW_STREAM_LISTERNER_EXCEPTION", ex.getMessage());
            }

            @Override
            public void onMessage(String rawString) {
                receive(rawString);
            }
        };

        FilterQuery fq = new FilterQuery();

        String keywords[] = tracks;

        if (follows != null && follows.length > 0)
            fq.follow(follows);
        else if (keywords != null && keywords.length > 0)
            fq.track(keywords);
        else if (locations != null)
            fq.locations(locations);
        else
            throw new Exception("INBOUND_TRANSPORT_NOFILTER_ERROR");

        fq.count(count);

        LOGGER.info("INBOUND_TRANSPORT_FILTER", filterString);

        twitterStream.addListener(rl);
        twitterStream.filter(fq);

    } catch (Throwable ex) {
        LOGGER.error("UNEXPECTED_ERROR", ex);
        setRunningState(RunningState.ERROR);
    }
}

From source file:com.example.leonid.twitterreader.Twitter.TwitterGetTweets.java

License:Apache License

@Override
protected List<CreateTweet> doInBackground(String... params) {
    mTweetsInfo = new ArrayList<>();
    List<String> texts = new ArrayList<>();
    List<String> titles = new ArrayList<>();
    List<String> images = new ArrayList<>();
    List<String> date = new ArrayList<>();
    if (!isCancelled()) {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET)
                .setOAuthAccessToken(ACCESS_KEY).setOAuthAccessTokenSecret(ACCESS_SECRET);
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();
        //query search result
        Query query = new Query(params[0]);
        //how much tweets need to be displayed(max 200)
        query.count(200);/*from w w  w. jav  a2  s. c o  m*/
        try {
            mResult = twitter.search(query);
            for (twitter4j.Status status : mResult.getTweets()) {
                if (!isCancelled()) {
                    texts.add(status.getText());
                    titles.add(status.getUser().getName());
                    images.add(status.getUser().getBiggerProfileImageURL());
                    String cleanDate = status.getCreatedAt().toString();
                    date.add(cleanDate.substring(0, cleanDate.length() - 15) + " "
                            + cleanDate.substring(cleanDate.length() - 4));
                }
            }
        } catch (TwitterException e) {
            Log.e("exeption", e.toString());
        }
        //loop teuth results and create array list for list view
        for (int i = 0; i < texts.size(); i++) {
            mTweetsInfo.add(new CreateTweet(titles.get(i), images.get(i), texts.get(i), date.get(i)));
        }

    }
    return mTweetsInfo;
}

From source file:com.freedomotic.plugins.devices.twitter.gateways.TwitterGateway.java

License:Open Source License

public static synchronized Twitter getInstance(Config configuration) {
    if (twitter == null) {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        //TODO: create a default twitter account for freedom project. If the user do not customize the oauth parameters in
        //config file we can use by default the parameters of the freedom twitter account (the second argument in getStringProperty).
        cb.setDebugEnabled(true).setOAuthConsumerKey(configuration.getStringProperty("OAuthConsumerKey", null)) //"TLGtvoeABqf2tEG4itTUaw")
                .setOAuthConsumerSecret(configuration.getStringProperty("OAuthConsumerSecret", null)) //"nUJPxYR1qJmhX9SnWTBT0MzO7dIqUtNyVPfhg10wf0")
                .setOAuthAccessToken(configuration.getStringProperty("OAuthAccessToken", null))//"312792183-adnYVIv06spR4qsI3eKVv53CfrYHl3KqgtJtYm10")
                .setOAuthAccessTokenSecret(configuration.getStringProperty("OAuthAccessTokenSecret", null));//("Br2O2wtZ2dsLMDN21qKdlCLsOuqXW8h3z3uButRk");
        TwitterFactory tf = new TwitterFactory(cb.build());
        twitter = tf.getInstance();//w  w w .  j a  v  a  2  s .  c om
    }
    return twitter;
}

From source file:com.fsatir.twitter.TwitterManagedBean.java

public Twitter bringMyTwitterInstance() throws TwitterException {

    String consumerKey = TwitterInfos.CONSUMER_KEY.getCredentialValue();
    String consumerSecret = TwitterInfos.CONSUMER_SECRET.getCredentialValue();
    String oAuthToken = TwitterInfos.OAUTH_TOKEN.getCredentialValue();
    String oAuthSecret = TwitterInfos.OAUTH_SECRET.getCredentialValue();

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(consumerKey);
    builder.setOAuthConsumerSecret(consumerSecret);
    builder.setOAuthAccessToken(oAuthToken);
    builder.setOAuthAccessTokenSecret(oAuthSecret);
    Configuration configuration = builder.build();
    TwitterFactory factory = new TwitterFactory(configuration);
    Twitter twitter = factory.getInstance();
    return twitter;
}

From source file:com.fuzuapp.model.resultados.TwitterAdapter.java

private void inicializar() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("56dJMai5O3H1MUjUl607LPgOh")
            .setOAuthConsumerSecret("wLsRXEDxDWAgOW217XbSiSK1J2WNG2gqxVDuLIqreI5VYfKEyD")
            .setOAuthAccessToken("64546879-myofEJ5cfPHwaRIud8mSBq2BmM68gHo9gGNgvj8Qb")
            .setOAuthAccessTokenSecret("dzJYWMs4QJUAwOCTisg5eSVLT5xhTp61ecuZ6fNpnARAI");
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();/*  w w w . ja v a2s.  c om*/

}

From source file:com.github.altyjp.webChangeDetector.TweetStrings.java

/**
 * ?// ww  w.j a v a2  s  .  c  om
 *
 * @param str_tweet
 * @throws TwitterException
 */
public void tweetString(String str_tweet) throws TwitterException {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(ConsumerKey).setOAuthConsumerSecret(ConsumerSecret)
            .setOAuthAccessToken(AccessToken).setOAuthAccessTokenSecret(AccessTokenSecret);
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();

    //User user = twitter.verifyCredentials();
    //?
    //System.out.println("???" + user.getName());
    //System.out.println("?????" + user.getScreenName());
    //System.err.println("???" + user.getFriendsCount());
    //System.out.println("????" + user.getFollowersCount());
    //??????
    Status status = twitter.updateStatus(str_tweet);
}

From source file:com.github.gorbin.asne.twitter.TwitterSocialNetwork.java

License:Open Source License

private void initTwitterClient() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(fConsumerKey);
    builder.setOAuthConsumerSecret(fConsumerSecret);

    String accessToken = mSharedPreferences.getString(SAVE_STATE_KEY_OAUTH_TOKEN, null);
    String accessTokenSecret = mSharedPreferences.getString(SAVE_STATE_KEY_OAUTH_SECRET, null);

    TwitterFactory factory = new TwitterFactory(builder.build());

    if (TextUtils.isEmpty(accessToken) && TextUtils.isEmpty(accessTokenSecret)) {
        mTwitter = factory.getInstance();
    } else {//from ww  w .j  a  va  2s.  c  o  m
        mTwitter = factory.getInstance(new AccessToken(accessToken, accessTokenSecret));
    }
}

From source file:com.github.hiro2k.logback.twitter.TwitterAppender.java

License:Apache License

@Override
public void start() {
    boolean requiredPropsSet = true;
    if (getAccessToken() == null) {
        addStatus(new ErrorStatus("Access token not set", this));
        requiredPropsSet = false;/*ww w.j a v a 2 s  .  c o m*/
    }
    if (getAccessSecret() == null) {
        addStatus(new ErrorStatus("Access secret not set", this));
        requiredPropsSet = false;
    }
    if (getConsumerKey() == null) {
        addStatus(new ErrorStatus("Consumer key not set", this));
        requiredPropsSet = false;
    }
    if (getConsumerSecret() == null) {
        addStatus(new ErrorStatus("Consumer Secret not set", this));
        requiredPropsSet = false;
    }
    if (!requiredPropsSet && twitter == null) {
        addWarn("Appender not started because the required properties weren't all set.");
        return;
    }
    if (layout == null) {
        layout = makeDefaultPatternLayout();
    }
    if (twitter == null) {
        ConfigurationBuilder configBuilder = new ConfigurationBuilder();
        configBuilder.setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret)
                .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessSecret);
        TwitterFactory tf = new TwitterFactory(configBuilder.build());
        this.twitter = tf.getInstance();
    }
    super.start();
}