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.tweetmap.utilities.Data.java

public static ConfigurationBuilder getConf() {
    configBuilder = new ConfigurationBuilder();
    configBuilder.setDebugEnabled(true);
    configBuilder.setOAuthConsumerKey("KreBXMpmyq6PrlSfMRdjIOGxO");
    configBuilder.setOAuthConsumerSecret("EWf8IEY4IdoDheB13rBiqjomxflQggvoIJakzq83h9EhFANu29");
    configBuilder.setOAuthAccessToken("2656744184-CIsaRR7wuAf1Gt89o0YE8F4ZVMMsS7wzDRBmBtW");
    configBuilder.setOAuthAccessTokenSecret("IRphexX0N5ivq93dFW4b0pQYkk0hvOu6rS3IMeOVIstYV");

    return configBuilder;
}

From source file:com.tweetmyhome.TweetMyHome.java

public TweetMyHome() throws TweetMyHomeException, IOException, TweetStringException {

    Log.setLogger(new MyCustomLogger());
    p = new TweetMyHomeProperties();
    if (!p.isFirstTimeCreated()) {
        if (p.getValueByKey(Key.debuggin).equalsIgnoreCase("true")) {
            Log.set(Log.LEVEL_DEBUG);//www  .j a v  a2s  . com
            Log.set(Log.LEVEL_TRACE);
        } else {
            Log.set(Log.LEVEL_INFO);
        }
    } else {
        File file = new File(TweetMyHomeProperties.FILE_NAME);
        info(String.format("Properties file created at: %s", file.getAbsolutePath()));
        info(String.format("Please edit '%s' to correct aplication function", TweetMyHomeProperties.FILE_NAME));
        info("Exiting aplication...");
        System.exit(0);
    }
    tweetCount = new TweetMensajeCount(COUNT_FILE);
    tmh_device_xml = XMLFilesManager.getTweetMyHomeDevices();
    if (tmh_device_xml == null) {
        throw new TweetMyHomeException(
                "Fail to read [" + XMLFilesManager.TWEET_MY_HOME_DEVICES_XML_FILE + "] file");
    }
    tmh_dic_xml = XMLFilesManager.getTweetMyHomeDictionaryCommand();
    if (tmh_dic_xml == null) {
        throw new TweetMyHomeException(
                "Fail to read [" + XMLFilesManager.TWEET_MY_HOME_DICTIONARY_XML_FILE + "] file");
    }
    tweetDictionary = new TweetStringDictionary(tmh_dic_xml);
    trace("XML Files already Readed [" + XMLFilesManager.TWEET_MY_HOME_DEVICES_XML_FILE + ","
            + XMLFilesManager.TWEET_MY_HOME_DICTIONARY_XML_FILE + "]");

    if (!NetUtil.isConnectedToInternet() && INTERNET_REQUIRED_DEV) {
        throw new TweetMyHomeException("Not Connected to Internet");
    }
    trace("Internet conecction detected");
    trace("Trying to connect to DBMS...");
    db = new TweetMyHomeDatabase(p);
    if (!db.connect()) {
        throw new TweetMyHomeException("Not Connected to DBMS");
    }
    trace("Connected to DBMS");
    db.addTweetMyHomeDevices(tmh_device_xml);

    if (RASPBERRY_ON_BOARD) {
        if (p.getValueByKey(Key.arduinoIOBridge).equalsIgnoreCase("true")) {
            throw new TweetMyHomeException("Arduino not supported...");
        } else {
            iob = new RaspberryPiGPIO(tmh_device_xml);
        }
        if (iob != null) {
            iob.addIODeviceListener(this);
            iob.connect();
            trace("GPIO Link established");
            com = new Comunity(false, iob);
            sec = new Security(false, iob);
            //sect = new SecurityThreshhold(sec);
            trace("Security , Security threshold & Comunity initiated");
        }
    } else {
        warn("Raspberry PI GPIO omited. APP prob. won't work well");
    }
    sect = new SecurityThreshhold(sec);
    trace("Setting Twitter OAuth parameters...");
    ConfigurationBuilder cb1 = new ConfigurationBuilder();
    cb1.setDebugEnabled(false).setOAuthConsumerKey("RaTG5hw5OwhQQugghtLthG0ug")
            .setOAuthConsumerSecret("brJ0vcrdGnCHMTxDCmKoThPpJubD6e2xol5WjdO9bBa19nzkXp")
            .setOAuthAccessToken("3236804811-V6MOxfbox4jVylx6pDjkR9UrEpuPzZyOwkaVIWp")
            .setOAuthAccessTokenSecret("33HvizelxmGN700a7pLa6YBKv0l2uTMLoJK593MlXellg");
    ConfigurationBuilder cb2 = new ConfigurationBuilder();
    cb2.setDebugEnabled(false).setOAuthConsumerKey("RaTG5hw5OwhQQugghtLthG0ug")
            .setOAuthConsumerSecret("brJ0vcrdGnCHMTxDCmKoThPpJubD6e2xol5WjdO9bBa19nzkXp")
            .setOAuthAccessToken("3236804811-V6MOxfbox4jVylx6pDjkR9UrEpuPzZyOwkaVIWp")
            .setOAuthAccessTokenSecret("33HvizelxmGN700a7pLa6YBKv0l2uTMLoJK593MlXellg");
    TwitterFactory tf = new TwitterFactory(cb1.build());
    TwitterStreamFactory sf = new TwitterStreamFactory(cb2.build());

    trace("Connecting to Twitter STREAM API...");
    tws = sf.getInstance();
    tws.addListener(this);
    tws.user();
    trace("Connecting to Twitter REST API...");
    tw = tf.getInstance();
    debug("Contructor fi");
    /*----------------NEEDED WORK TO DO-------------------*/

    // integrityCheckSuperAdmin();

}

From source file:com.twitt4droid.Twitt4droid.java

License:Apache License

/**
 * Gets the current twitter4j configuration with consumer and access tokens pre-initialized. You
 * can use this method to build a Twitter objects.
 * /*from   w  ww  .j av a2 s.c  o m*/
 * @param context the application context.
 * @return an Configuration object.
 */
private static Configuration getCurrentConfig(Context context) {
    SharedPreferences preferences = Resources.getPreferences(context);
    return new ConfigurationBuilder()
            .setOAuthConsumerKey(Resources.getMetaData(context,
                    context.getString(R.string.twitt4droid_consumer_key_metadata), null))
            .setOAuthConsumerSecret(Resources.getMetaData(context,
                    context.getString(R.string.twitt4droid_consumer_secret_metadata), null))
            .setOAuthAccessToken(
                    preferences.getString(context.getString(R.string.twitt4droid_oauth_token_key), null))
            .setOAuthAccessTokenSecret(
                    preferences.getString(context.getString(R.string.twitt4droid_oauth_secret_key), null))
            .build();
}

From source file:com.twitter.storm.hashtag2.TwitterSampleSpout.java

License:Apache License

public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    queue = new LinkedBlockingQueue<Status>(1000);
    _collector = collector;/*from  ww  w  . java2s . co  m*/

    StatusListener listener = new StatusListener() {

        public void onStatus(Status status) {

            queue.offer(status);
        }

        public void onDeletionNotice(StatusDeletionNotice sdn) {
        }

        public void onTrackLimitationNotice(int i) {
        }

        public void onScrubGeo(long l, long l1) {
        }

        public void onException(Exception ex) {
        }

        public void onStallWarning(StallWarning arg0) {
            // TODO Auto-generated method stub

        }

    };

    ConfigurationBuilder cb = new ConfigurationBuilder();

    cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret)
            .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret);

    _twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    _twitterStream.addListener(listener);

    if (keyWords.length == 0) {
        _twitterStream.sample();
    } else {
        FilterQuery query = new FilterQuery().track(keyWords);
        _twitterStream.filter(query);
    }
}

From source file:com.twitter.TwitterClient.java

public Configuration getConfiguration() {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setJSONStoreEnabled(true).setOAuthConsumerKey(OAUTHCONSUMERKEY).setOAuthConsumerSecret(OAUTHCONSECRET)
            .setOAuthAccessToken(OAUTHACCESSTOKEN).setOAuthAccessTokenSecret(OAUTHACCESSTOKENSECRET);
    Configuration configuration = cb.build();

    return configuration;

}

From source file:com.twitter4rk.TwitterAuthFragment.java

License:Apache License

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mTwitterWebView = new WebView(getActivity());
    final Bundle args = getArguments();
    if (args == null) {
        // This wont be case because startTwitterAuth() handles args for
        // fragment
        throw new IllegalArgumentException(
                "No arguments passed to fragment, Please use startTwitterAuth(...) method for showing this fragment");
    }/*from w  w w.ja  v  a2s. co m*/
    // Get builder from args
    mBuilder = args.getParcelable(BUILDER_KEY);
    // Hide action bar
    if (mBuilder.hideActionBar)
        mBuilder.activity.getActionBar().hide();
    // Init progress dialog
    mProgressDialog = new ProgressDialog(mBuilder.activity);
    mProgressDialog.setMessage(mBuilder.progressText == null ? "Loading ..." : mBuilder.progressText);
    if (mBuilder.isProgressEnabled)
        mProgressDialog.show();

    // Init ConfigurationBuilder twitter4j
    final ConfigurationBuilder cb = new ConfigurationBuilder();
    if (mBuilder.isDebugEnabled)
        cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey(mBuilder.consumerKey);
    cb.setOAuthConsumerSecret(mBuilder.consumerSecret);

    // Web view client to handler url loading
    mTwitterWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // Get url first
            final Uri uri = Uri.parse(url);
            // Check if we need to see for callback URL
            if (mBuilder.callbackUrl != null && url.contains(mBuilder.callbackUrl)) {
                // Get req info
                String oauthToken = uri.getQueryParameter("oauth_token");
                String oauthVerifier = uri.getQueryParameter("oauth_verifier");
                if (mListener != null)
                    mListener.onSuccess(oauthToken, oauthVerifier);
                if (mBuilder.isActionBarVisible && mBuilder.hideActionBar && getActivity() != null)
                    getActivity().getActionBar().show();
                mIsAuthenticated = true;
                removeMe();
                return true;
                // If no callback URL then check for info directly
            } else if (uri.getQueryParameter("oauth_token") != null
                    && uri.getQueryParameter("oauth_verifier") != null) {
                // Get req info
                String oauthToken = uri.getQueryParameter("oauth_token");
                String oauthVerifier = uri.getQueryParameter("oauth_verifier");
                if (mListener != null)
                    mListener.onSuccess(oauthToken, oauthVerifier);
                if (mBuilder.isActionBarVisible && mBuilder.hideActionBar && getActivity() != null)
                    getActivity().getActionBar().show();
                mIsAuthenticated = true;
                removeMe();
                return true;
                // If nothing then its failure
            } else {
                // Notify user
                if (mListener != null)
                    mListener.onFailure(
                            new Exception("Couldn't find the callback URL or oath parameters in response"));
                if (mBuilder.isActionBarVisible && mBuilder.hideActionBar && getActivity() != null)
                    getActivity().getActionBar().show();
                removeMe();
                return false;
            }
        }
    });
    // Web Crome client to handler progress dialog visibility
    mTwitterWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress == 100) {
                if (mProgressDialog.isShowing())
                    mProgressDialog.dismiss();
            }
        }
    });
    final Handler handler = new Handler();
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                final TwitterFactory twitterFactory = new TwitterFactory(cb.build());
                final Twitter twitter = twitterFactory.getInstance();
                RequestToken requestToken = null;
                if (mBuilder.callbackUrl == null)
                    requestToken = twitter.getOAuthRequestToken();
                else
                    requestToken = twitter.getOAuthRequestToken(mBuilder.callbackUrl);
                final RequestToken finalRequestToken = requestToken;
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        final String url = finalRequestToken.getAuthorizationURL();
                        mTwitterWebView.loadUrl(url);
                    }
                });
            } catch (TwitterException e) {
                e.printStackTrace();
            }
        }
    }).start();

    return mTwitterWebView;
}

From source file:com.unisa.flume.source.TwitterSource.java

License:Apache License

/**
 * 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.
 *//*from w  w w.  ja  va2  s .  c om*/
@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);

    String keywordString = context.getString(TwitterSourceConstants.KEYWORDS_KEY, "");
    if (keywordString.trim().length() == 0) {
        keywords = new String[0];
    } else {
        keywords = keywordString.split(",");
        for (int i = 0; i < keywords.length; i++) {
            keywords[i] = keywords[i].trim();
        }
    }

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

From source file:com.vti.managers.AccountManager.java

License:Apache License

public AccountManager(Context ctxt) {
    this.context = ctxt;
    final SharedPreferences settings = context.getSharedPreferences(Constants.AUTHORIZATION_PREFERENCE_FILE, 0);
    String accessToken = settings.getString(Constants.ACCESS_TOKEN, null);
    String tokenSecret = settings.getString(Constants.TOKEN_SECRET, null);

    if (null != accessToken && null != tokenSecret) {
        tf = new TwitterFactory(new ConfigurationBuilder().setDebugEnabled(true)
                .setOAuthConsumerKey(Constants.CONSUMER_KEY).setOAuthConsumerSecret(Constants.CONSUMER_SECRET)
                .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(tokenSecret).build());
    }/*from  w  w  w  . ja  v  a 2s  .  co  m*/
}

From source file:com.vuze.client.plugins.twitter.TwitterPlugin.java

License:Open Source License

private TwitterResult sendTweet(String status) {
    TwitterResult twitter_result;/*  w  w w  .  ja va  2s.co m*/

    log.log("Updating status: " + status);

    try {
        ConfigurationBuilder cb = new ConfigurationBuilder();

        //cb.setSource( "Vuze" );

        // Twitter twitter = new TwitterFactory( cb.build()).getInstance( twitter_user.getValue(), new String( twitter_password.getValue()));

        Status result;

        Twitter twitter = null;

        try {
            if (access_token == null) {

                throw (new Exception("Please configure your account settings in the plugin options"));
            }

            cb.setOAuthAccessToken(access_token.getToken())
                    .setOAuthAccessTokenSecret(access_token.getTokenSecret()).setOAuthConsumerKey(CONSUMER_KEY)
                    .setOAuthConsumerSecret(CONSUMER_SECRET);

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

            result = twitter.updateStatus(status);

        } catch (Throwable e) {

            // hack for old clients that don't have correct trust store

            if (twitter != null && (e instanceof TwitterException)
                    && ((TwitterException) e).getStatusCode() == -1) {

                String truststore_name = FileUtil.getUserFile(SESecurityManager.SSL_CERTS).getAbsolutePath();

                File target = new File(truststore_name);

                if (!target.exists() || target.length() < 2 * 1024) {

                    File cacerts = new File(
                            new File(new File(System.getProperty("java.home"), "lib"), "security"), "cacerts");

                    if (cacerts.exists()) {

                        FileUtil.copyFile(cacerts, target);
                    }
                }

                // this merely acts to trigger a load of the keystore

                plugin_interface.getUtilities().getSecurityManager()
                        .installServerCertificate(new URL("https://twitter.com/"));

                result = twitter.updateStatus(status);

            } else {

                throw (e);
            }
        }

        log.log("Status updated to '" + result.getText() + "'");

        twitter_result = new TwitterResult();

    } catch (TwitterException e) {

        int status_code = e.getStatusCode();

        if (status_code == 401) {

            log.logAlert(LoggerChannel.LT_ERROR, "Twitter status update failed: id or password incorrect");

            twitter_result = new TwitterResult("Authentication failed: ID or password incorrect", false);

        } else if (status_code == 403) {

            log.logAlert(LoggerChannel.LT_ERROR,
                    "Twitter status update failed: duplicate tweet rejected by the server");

            twitter_result = new TwitterResult("Tweet has already been sent!", false);

        } else if (status_code >= 500 && status_code < 600) {

            log.logAlert(LoggerChannel.LT_ERROR,
                    "Twitter status update failed: Twitter is down or being upgraded");

            twitter_result = new TwitterResult("Tweet servers unavailable - try again later", true);

        } else {

            log.logAlert("Twitter status update failed", e);

            twitter_result = new TwitterResult(Debug.getNestedExceptionMessage(e), false);
        }
    } catch (Throwable e) {

        log.logAlert("Twitter status update failed", e);

        twitter_result = new TwitterResult(Debug.getNestedExceptionMessage(e), false);
    }

    return (twitter_result);
}

From source file:com.wavemaker.runtime.ws.TwitterFeedService.java

License:Open Source License

private Twitter getTwitter() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(OAuthConsumerKey).setOAuthConsumerSecret(OAuthConsumerSecret)
            .setOAuthAccessToken(OAuthAccessToken).setOAuthAccessTokenSecret(OAuthAccessTokenSecret);

    return new TwitterFactory(cb.build()).getInstance();
}