Example usage for twitter4j TwitterFactory TwitterFactory

List of usage examples for twitter4j TwitterFactory TwitterFactory

Introduction

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

Prototype

public TwitterFactory() 

Source Link

Document

Creates a TwitterFactory with the root configuration.

Usage

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);/*from w w w.  j a v  a 2  s .  c om*/

}

From source file:me.chester.myretweetedtweets.User.java

License:Apache License

public User() {
    twitter = new TwitterFactory().getInstance();
    twitter.setOAuthConsumer(Config.CONSUMER_KEY, Config.CONSUMER_SECRET);
}

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 {/*from   ww w  . j  a  v  a  2 s .  com*/
        getLogger().info("Twitter is switched off you doughnut.");
        return null;
    }
}

From source file:miproyectolunadepluton.MiProyectoLunaDePluton.java

/**
 * @param args the command line arguments
 *//*from w  w  w.j av  a 2s .  co  m*/
public static void main(String[] args) throws TwitterException {
    /* ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)      
      .setOAuthConsumerKey("BNmJ2oaezMC2qciIgkpC33kYq")
    .setOAuthConsumerSecret("1b0xCDy2Qh5nFWeuJjdF1MDcjpVJTh4LSpjTfUKeabacirUOn4")
    .setOAuthAccessToken("708080587068858368-FxuwrHLsox7xVSQRbwjDV14vOpSxNyN")
    .setOAuthAccessTokenSecret("c4gBOfVZL7MwyhI7jVPVrGupnNJAiZAJ2cDE9qp48OVl1");*/
    TwitterFactory tf = new TwitterFactory();
    Twitter mitwitter = tf.getInstance();
    for (int i = 0; i < 11150; i++) {
        Status mistatus = mitwitter.updateStatus("Me la bufa");
        System.out.println(mistatus.getText());

    }
}

From source file:mitwitter.MiTwitter.java

/**
 * @param args the command line arguments
 *//*from www. ja v a  2s  .  co m*/
public static void main(String[] args) throws TwitterException {
    // TODO code application logic here

    //camobios

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

    //CODIGO CAMBIAR ESTADO
    Status miStatus = twitter.updateStatus("Tercer ejemplo");//cambia el estado de twitter
    System.out.println(miStatus.getText());

    //CODIGO TIMELINE
    List<Status> statuses = twitter.getHomeTimeline();
    System.out.println("Showing home timeline.");//aparecen los ultimos twitts
    for (Status status : statuses) {
        System.out.println(status.getUser().getName() + ":" + status.getText());
    }

    //CODIGO BUSCAR TAGS
    Query query = new Query("Chelsea"); //Dentro del String va el tag que quieres buscar
    QueryResult result = twitter.search(query);
    for (Status status : result.getTweets()) {
        System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
    }

}

From source file:net.awairo.favdler.oauth.TwitterOAuth.java

License:MIT License

/**
 * ????./*from  w  w  w  .  ja v a  2  s .  c  o m*/
 */
public void start() {
    FxUtils.checkFxApplicationThread();

    twitter = Optional.ofNullable(new TwitterFactory().getInstance());
    server.restart();
}

From source file:net.bluemix.droneselfie.TwitterUtilities.java

License:Open Source License

private String tweet(String pictureId, String message) {
    String output = null;/*  w  ww . ja  v a  2  s.c  o m*/
    if (message == null)
        return null;
    if (message.equalsIgnoreCase(""))
        return null;

    try {
        String consumerKey = ConfigUtilities.getSingleton().getTwitterConsumerKey();
        String consumerSecret = ConfigUtilities.getSingleton().getTwitterConsumerSecret();
        String accessToken = ConfigUtilities.getSingleton().getTwitterAccessToken();
        String accessTokenSecret = ConfigUtilities.getSingleton().getTwitterAccessTokenSecret();

        TwitterFactory twitterFactory = new TwitterFactory();
        Twitter twitter = twitterFactory.getInstance();
        twitter.setOAuthConsumer(consumerKey, consumerSecret);
        twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));

        StatusUpdate statusUpdate = new StatusUpdate(message);

        AttachmentInputStream data = DatabaseUtilities.getSingleton().getDB().getAttachment(pictureId,
                pictureId);
        statusUpdate.setMedia("picture", data);

        Status status = twitter.updateStatus(statusUpdate);
        if (status == null)
            return null;
        output = "https://twitter.com/bluedroneselfie/status/" + String.valueOf(status.getId());

        return output;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return output;
}

From source file:net.bluemix.newsaggregator.TwitterUtilities.java

License:Open Source License

private String tweet(String message) {
    String output = null;/*from   www .  j  a v a 2s .  c o m*/
    if (message == null)
        return null;
    if (message.equalsIgnoreCase(""))
        return null;

    try {
        String consumerKey = ConfigUtilities.getSingleton().getTwitterConsumerKey();
        String consumerSecret = ConfigUtilities.getSingleton().getTwitterConsumerSecret();
        String accessToken = ConfigUtilities.getSingleton().getTwitterAccessToken();
        String accessTokenSecret = ConfigUtilities.getSingleton().getTwitterAccessTokenSecret();

        TwitterFactory twitterFactory = new TwitterFactory();
        Twitter twitter = twitterFactory.getInstance();
        twitter.setOAuthConsumer(consumerKey, consumerSecret);
        twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));

        StatusUpdate statusUpdate = new StatusUpdate(message);

        Status status = twitter.updateStatus(statusUpdate);
        if (status == null)
            return null;
        output = "https://twitter.com/BluemixInfo/status/" + String.valueOf(status.getId());

        return output;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return output;
}

From source file:net.chrissearle.flickrvote.service.cli.TwitterOAuthCLI.java

License:Apache License

public void authorize(String key, String secret) throws TwitterException, IOException {
    Twitter twitter = new TwitterFactory().getInstance();

    twitter.setOAuthConsumer(key, secret);

    RequestToken requestToken = twitter.getOAuthRequestToken();

    AccessToken accessToken = null;//from ww  w. j  a  v  a  2  s.com

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    while (null == accessToken) {
        System.out.println("Open the following URL and grant access to your account:");
        System.out.println(requestToken.getAuthorizationURL());
        System.out.print("Enter the PIN(if available) or just hit enter.[PIN]:");

        String pin = br.readLine();
        try {
            if (pin.length() > 0) {
                accessToken = twitter.getOAuthAccessToken(requestToken, pin);
            } else {
                accessToken = twitter.getOAuthAccessToken();
            }

            System.out.println("Token: " + accessToken.getToken());
            System.out.println("TokenSecret: " + accessToken.getTokenSecret());
        } catch (TwitterException te) {
            if (401 == te.getStatusCode()) {
                System.out.println("Unable to get the access token.");
            } else {
                te.printStackTrace();
            }
        }
    }
}

From source file:net.chrissearle.spring.twitter.spring.TwitterFactoryBean.java

License:Apache License

public Twitter getObject() {
    return new TwitterFactory().getOAuthAuthorizedInstance(this.consumerKey, this.consumerSecret,
            this.accessToken);
}