Example usage for twitter4j TwitterFactory getInstance

List of usage examples for twitter4j TwitterFactory getInstance

Introduction

In this page you can find the example usage for twitter4j TwitterFactory getInstance.

Prototype

public Twitter getInstance() 

Source Link

Document

Returns a instance associated with the configuration bound to this factory.

Usage

From source file:io.warp10.script.functions.TWITTERDM.java

License:Apache License

@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
    ////from   ww  w.  j a v  a  2  s.  c  om
    // Extract parameters
    //

    String text = stack.pop().toString();
    String recipient = stack.pop().toString();
    String accessSecret = stack.pop().toString();
    String accessToken = stack.pop().toString();
    String consumerSecret = stack.pop().toString();
    String consumerKey = stack.pop().toString();

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret)
            .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessSecret);
    TwitterFactory tf = new TwitterFactory(cb.build());

    Twitter twitter = tf.getInstance();

    try {
        twitter.sendDirectMessage(recipient, text);
    } catch (TwitterException te) {
        throw new WarpScriptException("Error while sending Twitter Direct Message", te);
    }

    return stack;
}

From source file:it.baywaylabs.jumpersumo.PilotingActivity.java

License:Open Source License

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_piloting);

    initIHM();//from  w w  w .j  a  v  a  2  s.c  o m
    initVideo();

    Intent intent = getIntent();
    service = intent.getParcelableExtra(EXTRA_DEVICE_SERVICE);

    TwitterFactory twitterFactory = new TwitterFactory();
    this.twitter = twitterFactory.getInstance();
    twitter.setOAuthConsumer(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);
    twitter.setOAuthAccessToken(new AccessToken(Constants.ACCESS_TOKEN, Constants.ACCESS_TOKEN_SECRET));

    //create the device
    try {
        device = new ARDiscoveryDevice();

        ARDiscoveryDeviceNetService netDeviceService = (ARDiscoveryDeviceNetService) service.getDevice();

        this.ip_host = netDeviceService.getIp();

        device.initWifi(ARDISCOVERY_PRODUCT_ENUM.ARDISCOVERY_PRODUCT_JS, netDeviceService.getName(),
                netDeviceService.getIp(), netDeviceService.getPort());
    } catch (ARDiscoveryException e) {
        e.printStackTrace();
        Log.e(TAG, "Error: " + e.getError());
    }

    if (device != null) {
        try {
            //create the deviceController
            deviceController = new ARDeviceController(device);
            deviceController.addListener(this);
            deviceController.addStreamListener(this);
        } catch (ARControllerException e) {
            e.printStackTrace();
        }
    }
}

From source file:it.polimi.meteocal.ejb.HandleAuthTwitterImpl.java

License:Open Source License

/**
 * Method that return the Twitter object that allows the access to the
 * Twitter API/*from www  .  j a v a2s  . c  om*/
 *
 * @param user the user in MeteoCal
 * @return null if there was a problem with the creation of the Twitter
 * object
 */
public static Twitter getTwitterObject(User user) {
    Twitter twitter;

    if (user.getTwitterToken() == null) {
        // Twitter not connected
        return null;
    }

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(CLIENT_ID);
    builder.setOAuthConsumerSecret(CLIENT_SECRET);
    Configuration configuration = builder.build();
    TwitterFactory factory = new TwitterFactory(configuration);
    twitter = factory.getInstance();

    AccessToken at = new AccessToken(user.getTwitterToken(), user.getTwitterTokenSecret());
    LOGGER.log(Level.INFO, at);
    try {
        twitter.setOAuthAccessToken(at);
    } catch (Exception e) {
        LOGGER.log(Level.ERROR, e);
        return null;
    }
    return twitter;
}

From source file:it.polimi.meteocal.ejb.HandleAuthTwitterImpl.java

License:Open Source License

/**
 * Default constructor./*  w  ww  .  j av  a 2  s  .  c om*/
 */
public HandleAuthTwitterImpl() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(CLIENT_ID);
    builder.setOAuthConsumerSecret(CLIENT_SECRET);
    Configuration configuration = builder.build();
    TwitterFactory factory = new TwitterFactory(configuration);
    twitter = factory.getInstance();
    cont = 0;
}

From source file:it.polimi.meteocal.ejb.HandleAuthTwitterImpl.java

License:Open Source License

@Override
public String getUrlLoginTwitter() {
    String urlLogin = "error.xhtml";

    try {/*w w w  .  j  a v  a  2 s  .c  om*/
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthConsumerKey(CLIENT_ID);
        builder.setOAuthConsumerSecret(CLIENT_SECRET);
        Configuration configuration = builder.build();
        TwitterFactory factory = new TwitterFactory(configuration);
        twitter = factory.getInstance();
        //if (requestToken == null) {
        requestToken = twitter.getOAuthRequestToken(URL_BASE + "/MeteoCal-web/loginTwitter.xhtml");
        //}
        urlLogin = requestToken.getAuthenticationURL();
    } catch (TwitterException e) {
        LOGGER.log(Level.ERROR, e);
    }
    cont++;
    LOGGER.log(Level.INFO, "Conteggio: " + cont);
    LOGGER.log(Level.INFO, "URL LOGIN " + urlLogin);
    return urlLogin;
}

From source file:jp.co.tweetmap.util.TwitterUtils.java

License:Apache License

/**
 * Gets the Twitter instance. Access token is automatically set if it is saved.
 *
 * @param context {@link Context}, not {@code null}.
 * @return Twitter instance.//w w  w .jav  a2s.co  m
 */
public static Twitter getTwitterInstance(Context context) {
    String consumerKey = context.getString(R.string.twitter_consumer_key);
    String consumerSecret = context.getString(R.string.twitter_consumer_secret_key);

    TwitterFactory factory = new TwitterFactory();
    Twitter twitter = factory.getInstance();
    twitter.setOAuthConsumer(consumerKey, consumerSecret);

    if (hasAccessToken(context)) {
        twitter.setOAuthAccessToken(loadAccessToken(context));
    }
    return twitter;
}

From source file:junit.org.rapidpm.module.iot.twitter.TwitterInitApp.java

License:Apache License

public static void main(String[] args) throws TwitterException {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("DI0UZvexwirEJ1wl5sw9Vfqx3")
            .setOAuthConsumerSecret("NQ0Zumw7Li1XbuwzrNHOKquznBgmAJo1sPAoqiNMShqgFufqip")
            .setOAuthAccessToken("2440296835-4dmuWPOLYUgLjn9ddcXpuloOgDAPO1W0Y5NZSg7")
            .setOAuthAccessTokenSecret("X9QYzlDKURIxGZbFWoZ7NdvhcFurBfEUVHMTLxtBSrU2x");

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

    twitter.getHomeTimeline().forEach(s -> System.out.println("s.getText() = " + s.getText()));

}

From source file:main.Config.java

License:Creative Commons License

public static void accsesTokenLoad() {

    TwitterFactory factory = new TwitterFactory();
    AccessToken token = new AccessToken(getAccessToken(), getTokenSecret());
    Frame.twitter = factory.getInstance();
    Frame.twitter.setOAuthAccessToken(token);

    System.out.println(token);//ww  w.j a v  a 2 s. c om

}

From source file:mashup.MashTweetManager.java

public static ArrayList<String> getTweets(String topic) throws IOException {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthAccessToken(Common.AccessToken)
            .setOAuthAccessTokenSecret(Common.AccessTokenSecret).setOAuthConsumerKey(Common.ConsumerKey)
            .setOAuthConsumerSecret(Common.ConsumerSecret);

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

    //Twitter twitter = new TwitterFactory().getInstance();

    //  twitter.setOAuthAccessToken(null);

    ArrayList<String> tweetList = new ArrayList<>();

    try {/* w  w w . j  a  v  a2s. c o  m*/
        Query query = new Query(topic.toLowerCase().trim());

        query.setCount(100);
        query.setLocale("en");
        query.setLang("en");

        QueryResult result = null;

        do {
            result = twitter.search(query);
            List<Status> tweets = result.getTweets();

            for (Status tweet : tweets) {
                String data = tweet.getText().replaceAll("[^\\p{L}\\p{Z}]", "");

                HinghlishStopWords.removeStopWords(data.trim());
                // Remove Special... Characters 
                // Remove stop words 
                tweetList.add(tweet.getText().replaceAll("[^\\p{L}\\p{Z}]", ""));

            }

        } while ((query = result.nextQuery()) != null);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to search tweets: " + te.getMessage());
    }
    return tweetList;
}

From source file:mineTwit.Main.java

License:Open Source License

private Twitter setupTwitter(twitterSettings setupSettings) throws TwitterException {
    // TODO Debug lines to be removed later
    //getLogger().info("[setupTwitter][DEBUG]Status is " + setupSettings.status);
    //getLogger().info("[setupTwitter][DEBUG]apiKey is " + setupSettings.apiKey);
    //getLogger().info("[setupTwitter][DEBUG]apiSecret is " + setupSettings.apiSecret);
    //getLogger().info("[setupTwitter][DEBUG]token is " + setupSettings.token);
    //getLogger().info("[setupTwitter][DEBUG]secret is " + setupSettings.secret);
    //if (TWITTER_CONFIGURED) {
    if (setupSettings.status) {
        TwitterFactory factory = new TwitterFactory();
        final Twitter twitter = factory.getInstance();
        AccessToken accessToken = loadAccessToken(setupSettings.token, setupSettings.secret);
        authenticateTwitter(accessToken, twitter, setupSettings.apiKey, setupSettings.apiSecret);
        currentMessage = getCurrentStatus(twitter);
        getLogger().info("Twitter is enabled.");
        getLogger().info("Last message was - " + currentMessage);
        return twitter;
    } else {/*  www. ja  v  a 2s.c  om*/
        getLogger().info("Twitter is switched off you doughnut.");
        return null;
    }
}