Example usage for twitter4j Query count

List of usage examples for twitter4j Query count

Introduction

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

Prototype

int count

To view the source code for twitter4j Query count.

Click Source Link

Usage

From source file:twitterAPI.Twitter_testing.java

public void getSearchTweets(String regex) {
    //String queryStr = "@RobotGrrl";
    try {/*from   w w  w .j  ava  2 s  .c  o  m*/
        //Twitter twitter = TwitterFactory.getSingleton();
        Query query = new Query(regex);
        query.count(100);
        System.out.println(query.getCount());

        QueryResult result = twitter.search(query);
        for (Status status : result.getTweets()) {

            searchHandler sh = new searchHandler();
            sh.nama = status.getUser().getScreenName();
            sh.tweet = status.getText();

            StringBuffer address = new StringBuffer();
            address.append("http://twitter.com/#!/");
            address.append(sh.nama);
            address.append("/status/");
            address.append(status.getId());

            String theAddressYouWant = address.toString();
            sh.URL = theAddressYouWant;
            shholder.add(sh);
            //System.out.println(theAddressYouWant); ini buat test bener apa ga url nya , udah bener
            //System.out.println("@" + sh.nama + ":" + sh.tweet);
        }
    } catch (TwitterException e) {
        System.out.println("Search tweets: " + e);
    }
}

From source file:twitterbot.TwitterActions.java

public void searchTweetandRetweet(String hashtag) {
    Query query = new Query(hashtag);
    query.count(40);
    int check = 0;
    int alreadyused = 0;
    int remove = 0;

    try {/* w  w w.j  a va  2 s.  co  m*/
        QueryResult queryresult = this.twitter.search(query);
        this.tweets = (ArrayList<Status>) queryresult.getTweets();
        Collections.reverse(tweets);
        for (Status status : tweets) {
            if (!status.isRetweetedByMe() && status.getCreatedAt().getTime() > this.lastStatusTime) {
                try {
                    this.retweetTweet(status);
                    this.lastStatusTime = status.getCreatedAt().getTime();
                    this.writeTimeToFile();
                    Thread.sleep(10000);
                } catch (TwitterException tex) {
                    System.out.println("Twitter Exception - Already Retweeted");
                }
            }
        }
    } catch (TwitterException ex) {
        Logger.getLogger(TwitterActions.class.getName()).log(Level.SEVERE, null, ex);

    } catch (InterruptedException ex) {
        Logger.getLogger(TwitterActions.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:twittervis.TwitterVis.java

public void retrieveTweets(String keyword, boolean topic) {

    Twitter twitter = tf.getInstance();//from ww  w .  ja va2s.c o  m
    Query query = new Query(keyword);
    // The query parameter ("keyword") can be modified to make more
    // specific search queries based on language, users, time, etc.
    //Query query = new Query(keyword +" AND lang:en AND until:2016-12-01");

    //number of tweets needed for each topic.
    query.count(240);

    // Assign the tweets to the corresponding Emotion Node
    if (topic == true) {
        JoyNode = "Joy1";
        SadnessNode = "Sadness1";
        AngerNode = "Anger1";
        DisgustNode = "Disgust1";
        FearNode = "xFear1";
    } else {
        JoyNode = "Joy2";
        SadnessNode = "Sadness2";
        AngerNode = "Anger2";
        DisgustNode = "Disgust2";
        FearNode = "xFear2";
    }

    //Try making the query request.
    try {
        QueryResult result = twitter.search(query);

        // Process the analysis results and create new edges and nodes accordingly
        result.getTweets().forEach((status) -> {
            status.getText(); //get the textual info from a tweet
            // String userName = status.getUser().getScreenName();
            String TwtText = status.getText();
            System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
            String twtEmotion = getTweetEmotion(TwtText);

            // A switch to assign the tweet to the correct node
            switch (twtEmotion) {
            case "Joy":
                System.out.println("Joy (*^__^*)");
                graph.addEdge(TwtText, JoyNode, TwtText);
                break;
            case "Sadness":
                System.out.println("Sad (*T_T*)");
                graph.addEdge(TwtText, SadnessNode, TwtText);
                break;
            case "Anger":
                System.out.println("Anger ()");
                graph.addEdge(TwtText, AngerNode, TwtText);
                break;
            case "Fear":
                System.out.println("Fear ?|||");
                graph.addEdge(TwtText, FearNode, TwtText);
                break;
            case "Disgust":
                System.out.println("Disgust (*~)");
                graph.addEdge(TwtText, DisgustNode, TwtText);
                break;
            }
        });

    } catch (TwitterException ex) { //fallback if exceptions occur
        System.out.println("Couldn't connect: " + ex);
    }
}