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(String configTreePath) 

Source Link

Document

Creates a TwitterFactory with a specified config tree

Usage

From source file:ens.demo.twitter.TwittEmergencyMessage.java

@Override
public void run() {
    try {/*from   w  w w.  ja  v a  2s  . com*/
        if (toCustomer.getToken() == null || toCustomer.getToken().isEmpty()) {
            return;
        }
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Properties properties = new Properties();
        properties.load(classLoader.getResourceAsStream("twitter4j.properties"));
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey(properties.getProperty("twitter4j.oauth.consumerKey"))
                .setOAuthConsumerSecret(properties.getProperty("twitter4j.oauth.consumerSecret"))
                .setOAuthAccessToken(toCustomer.getToken())
                .setOAuthAccessTokenSecret(toCustomer.getTokenSecret());
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();
        StatusUpdate update = new StatusUpdate(message);
        Status status = twitter.updateStatus(update);
        System.out.println("Successfully updated the status to [" + status.getText() + "].");
    } catch (TwitterException ex) {
        Logger.getLogger(TwittEmergencyMessage.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(TwittEmergencyMessage.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:entities.TwitterFeed.java

public void initTimeline() {
    timelineFrame = new JFrame("@SIM_IST Timeline");

    timelineFrame.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();

    timelineBack = new JButton("Back");
    timelineBack.addActionListener(this);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0.5;//from w  w w . ja v a  2 s. co  m
    c.gridx = 1;
    c.gridy = 1;
    c.gridwidth = 1;
    timelineFrame.add(timelineBack, c);

    timelineTweets = new JTextArea();
    Font font = new Font("Gotham Narrow", Font.BOLD, 12);
    timelineTweets.setFont(font);
    timelineTweets.setEditable(false);
    timelineScrollPane = new JScrollPane(timelineTweets);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    c.ipady = 200;
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 3;
    timelineFrame.add(timelineScrollPane, c);

    KeyReader keys = new KeyReader();

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(keys.getConsumerKey())
            .setOAuthConsumerSecret(keys.getConsumerSecret()).setOAuthAccessToken(keys.getAccessToken())
            .setOAuthAccessTokenSecret(keys.getAccessTokenSecret());
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();
    try {
        System.out.println("timeline retreval worked");

        List<Status> statuses = twitter.getHomeTimeline();
        for (Status status : statuses) {
            timelineTweets
                    .append("@" + status.getUser().getScreenName() + " : " + status.getText() + "\n" + "\n");
            timelineTweets.setLineWrap(true);
            timelineTweets.setWrapStyleWord(true);
            timelineTweets.setCaretPosition(0);
            System.out.println("@" + status.getUser().getName() + " : " + status.getText());
        }

    } catch (TwitterException te) {
        System.out.print("timeline retreval failed");
        te.printStackTrace();
    }

    timelineFrame.pack();
    timelineFrame.setSize(600, 300);
    timelineFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    timelineFrame.setLocationRelativeTo(null);
    timelineFrame.setVisible(true);
}

From source file:entities.TwitterFeed.java

public void postTweet() {
    KeyReader keyreader = new KeyReader();

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(keyreader.getConsumerKey());
    cb.setOAuthConsumerSecret(keyreader.getConsumerSecret());
    cb.setOAuthAccessToken(keyreader.getAccessToken());
    cb.setOAuthAccessTokenSecret(keyreader.getAccessTokenSecret());

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

    try {/*  w  ww.ja  v  a2  s  .c  o  m*/
        tf.updateStatus(typeTweet.getText());
        System.out.println("tweet post success");

    } catch (TwitterException te) {
        System.out.println("tweet post failed");
        te.printStackTrace();
    }
}

From source file:erando.controllers.AddProductController.java

@FXML
private void addProductAction(ActionEvent event)
        throws FileNotFoundException, IOException, TwitterException, DocumentException {
    Product p = new Product();
    Sms sms = new Sms();
    ISms smsservice = new SmsService();
    IShopService productService = new ProductService();
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("YYYY:MM/HH:mm:ss");

    p.setTitre(pTitre.getText());/*from w  w w  .  ja  v a  2  s.c  o m*/
    p.setPrix(Integer.parseInt(pPrix.getText()));
    p.setDescription(pDescription.getText());
    p.setType(pType.getValue().toString());
    p.setDate(sdf.format(cal.getTime()));
    p.setImage(imageName);
    if (!pTitre.getText().isEmpty() && !pPrix.getText().isEmpty() && !pDescription.getText().isEmpty()
            && !pType.getValue().toString().isEmpty()) {
        productService.add(p);
        ////////send sms to subs
        sms.setNum("" + Parameters.user.getNumTel());
        sms.setMessagetel("Product Added To Store go check it !");
        smsservice.sendSms(sms);

        ////////share on facebook (when asked by the owner ! )
        if (shareFacebook.isSelected()) {
            String accessToken = "EAACEdEose0cBAKLtkZBKZCBoEkx4MApf3HxDMAR93PoJ6lAAuZAMdfY9vtob2ii78C6TN88hSV8HK0tDZBskaUz5pcbH1HqVeDRISuEHsG0qqUZBca4gHGnANPWcZBSZA9RNFHpbwVHJ46ITntn52SGQWetPPaZBsNlsFXbpcDrKytOVtmspQzfrM8GiUQtm1kQZD";
            FacebookClient fbClient = new DefaultFacebookClient(accessToken, Version.LATEST);
            File fs = new File("C:\\Users\\F.Mouhamed\\Desktop\\Esprit\\ERandoPi\\userfiles\\");
            fs.getParentFile().setExecutable(true);
            fs.getParentFile().setReadable(true);
            fs.getParentFile().setWritable(true);
            ////////FileInputStream fis = new FileInputStream(fs.getParentFile());
            User me = fbClient.fetchObject("me", User.class);
            FacebookType response;
            response = fbClient.publish("me/feed", FacebookType.class, Parameter.with("message",
                    p.getTitre() + "\n " + p.getDescription() + "\n Prix:" + p.getPrix()));
        }

        ////////share on twitter (when asked by the owner ! )
        if (shareTwitter.isSelected()) {
            ConfigurationBuilder cb = new ConfigurationBuilder();
            cb.setDebugEnabled(true).setOAuthConsumerKey("dHU6c4cXI6HDeLI3pakG8PYtp")
                    .setOAuthConsumerSecret("n0NxZVXgpEMGJboWYBSD1nfbaa3Ov2qL0e9h2GzyUsa8wQ0q0p")
                    .setOAuthAccessToken("729655065716346881-gukmKiOsT5WFv05t3yfQFrWgoPycQGD")
                    .setOAuthAccessTokenSecret("4qTGW5YdG8j9biJeAybzIcivCPZaAOqES2PhoJI9S7WKL");
            TwitterFactory tf = new TwitterFactory(cb.build());
            twitter4j.Twitter tw = tf.getInstance();
            String StatusMessage = ("Titre :" + p.getTitre() + "\nDescription:\n" + p.getDescription()
                    + "\nPrix:" + p.getPrix());
            StatusUpdate status = new StatusUpdate(StatusMessage);
            tw.updateStatus(status);
        }
        /////////show notification
        Notifications notificationBuilder = Notifications.create().title("sucess").text("produit ajouter")
                .graphic(null).hideAfter(Duration.seconds(4)).position(Pos.BOTTOM_RIGHT);
        notificationBuilder.darkStyle();
        notificationBuilder.showConfirm();
        /////////send emails to users subscribed to this type of product
        List<String> subs = productService.getSubscribes(p.getType());
        mailToSubs mails = new mailToSubs();
        for (String s : subs) {
            mails.envoyerfacture(s.toString(), p.getImage().toString(), p.getId(), p.getTitre(), p.getPrix(),
                    p.getDescription());
        }
    }
}

From source file:es.upm.oeg.entity.extractor.extractor.gate.TwitterCorpus.java

public void createCorpus() {

    repository = new FarolasRepo();

    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();//  w w  w . j a  v a  2  s  .c  o  m
    try {
        corpus = Factory.newCorpus("tweetcorpus");
        Query query = new Query(queryString); //"oddfarolas"
        QueryResult result;
        result = twitter.search(query);
        List<Status> tweets = result.getTweets();
        for (Status tweet : tweets) {
            Document doc = Factory.newDocument(tweet.getText());
            doc.setName(String.valueOf(tweet.getId()));
            corpus.add(doc);

            logger.info(tweet.getId() + "  @" + tweet.getUser().getScreenName() + " - " + tweet.getText() + " -"
                    + tweet.getGeoLocation());
            repository.instanciateNew(String.valueOf(tweet.getId()), tweet.getUser().getScreenName(),
                    tweet.getText(), tweet.getGeoLocation());

        }

    } catch (TwitterException te) {
        logger.error(te);
        logger.error("Failed to search tweets: " + te.getMessage());
        System.exit(-1);
    } catch (ResourceInstantiationException ex) {
        logger.error(ex);
    }
    logger.info("corpus size" + corpus.size());

}

From source file:examencodrecu.MetodosTwitter.java

public MetodosTwitter() {
    /*    ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)//ww w .  ja  v a2 s .c  o m
        .setOAuthConsumerKey("sfykEWIIWMM60T0apJFNGmc9n")
        .setOAuthConsumerSecret("DnFd8UbiNXcxoHhei4kQ4wMsctTHjI8MkW0fqVjCdSfdWaSBqW")
        .setOAuthAccessToken("867802357-6hZ73Bu9QVD8ExLFmeJkarBsmOXXNgBMZXxp3sH1")
        .setOAuthAccessTokenSecret("R9rGWgmyoUW5vz0wHypXNlgZn7F7ArU7mGf3Ibies6h6d");
            
        twitter = new TwitterFactory(cb.build()).getInstance();
    */
    twitter = new TwitterFactory("twitter4j.properties").getInstance();
}

From source file:examencodtwitter.Metodos.java

/**
         /*w w  w. j a  va 2 s.com*/
 */
public Metodos() {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("xxxxxxxxxx").setOAuthConsumerSecret("xxxxxxxxxxxxxxxxxxxxxx")
            .setOAuthAccessToken("xxxxxxxxxxxxxxxxxxxxxx")
            .setOAuthAccessTokenSecret("xxxxxxxxxxxxxxxxxxxxxxxxxx");

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

From source file:examendetwitter.metodostwitter.java

/**
 * Constructor, da acceso a nuestra cuenta en twitter.
 *///ww  w.j  a v  a2 s  .  c o m
public metodostwitter() {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("ttn86DHjTWZ21heKN6uQp9iy6")
            .setOAuthConsumerSecret("wQagAbytgoScb8UtCwY5nupQJkmW844MNrpMTVuQMFytxmceuP")
            .setOAuthAccessToken("3318200759-FsPeZSPibyDHgiPk7KllUBmvN5LarHeFpjH3JSv")
            .setOAuthAccessTokenSecret("z5I7uNEiIZH0ni9iNhKyUtASnHnGXN6puxjfQi6476RF0");
    twitter = new TwitterFactory(cb.build()).getInstance();
    twitter = new TwitterFactory("twitter4j.properties").getInstance();

}

From source file:examentwittercod.MetodosTwitter.java

/**
 * Costructores para acceder a twitter/*from w w  w  . ja  v  a2s  .c  o  m*/
 */
public MetodosTwitter() {

    /*ConfigurationBuilder cb = new ConfigurationBuilder();
     cb.setDebugEnabled(true)
     .setOAuthConsumerKey("*********")
     .setOAuthConsumerSecret("********")
     .setOAuthAccessToken("***********")
     .setOAuthAccessTokenSecret("*********");
            
    /*
     ----Aqui introduciriamos los nuestros datos personales de cada uno para poder acceder a nuestro twitter.----
            
            
     /*twitter = new TwitterFactory(cb.build()).getInstance();*/
    twitter = new TwitterFactory("twitter4j.properties").getInstance();

}

From source file:foo.bar.twitter.sample01.Sample01Activity.java

License:Apache License

/**
 * connect twitter/*w  w  w.  ja v a2s.  c  o  m*/
 */
private void connectTwitter() {
    ConfigurationBuilder confbuilder = new ConfigurationBuilder();
    confbuilder.setOAuthConsumerKey(ConstantValue.CONSUMER_KEY);
    confbuilder.setOAuthConsumerSecret(ConstantValue.CONSUMER_SECRET);
    Configuration conf = confbuilder.build();

    twitter = new TwitterFactory(conf).getInstance();
    twitter.setOAuthAccessToken(null);

    try {
        requestToken = twitter.getOAuthRequestToken(ConstantValue.CALLBACK_URL);
        Intent intent = new Intent(this, TwitterLoginActivity.class);
        intent.putExtra(ConstantValue.IEXTRA_AUTH_URL, requestToken.getAuthorizationURL());
        this.startActivityForResult(intent, 0);
    } catch (TwitterException e) {
        Toast.makeText(this, "Twitter Exception!!\n" + e.toString(), Toast.LENGTH_LONG).show();
    }
}