javatwittertwitter4j

how to get the full tweet of the user timeline with twitter4j?


I want to get tweets from certain user timelines using java library twitter4j, currently I have source code which can get ~ 3200 tweets from user time line but I can't get full tweet. I have searched in various sources on the internet but I can't find a solution to my problem. anyone can help me or can anyone provide an alternative to get a full tweet from the user timeline with java programming?

my source code :

public static void main(String[] args) throws SQLException {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true)
      .setOAuthConsumerKey("aaa")
      .setOAuthConsumerSecret("aaa")
      .setOAuthAccessToken("aaa")
      .setOAuthAccessTokenSecret("aaa");
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();

    int pageno = 1;
    String user = "indtravel";
    List statuses = new ArrayList();
    while (true) {
        try {
            int size = statuses.size();
            Paging page = new Paging(pageno++, 100);
            statuses.addAll(twitter.getUserTimeline(user, page));
            System.out.println("***********************************************");
            System.out.println("Gathered " + twitter.getUserTimeline(user, page).size() + " tweets");

            //get status dan user
            for (Status status: twitter.getUserTimeline(user, page)) {
                //System.out.println("*********Place Tweets :**************\npalce country :"+status.getPlace().getCountry()+"\nplace full name :"+status.getPlace().getFullName()+"\nplace name :"+status.getPlace().getName()+"\nplace id :"+status.getPlace().getId()+"\nplace tipe :"+status.getPlace().getPlaceType()+"\nplace addres :"+status.getPlace().getStreetAddress());
                System.out.println("["+(no++)+".] "+"Status id : "+status.getId());
                System.out.println("id user : "+status.getUser().getId());
                System.out.println("Length status :  "+status.getText().length());
                System.out.println("@" + status.getUser().getScreenName() +" . "+status.getCreatedAt()+ " : "+status.getUser().getName()+"--------"+status.getText());
                System.out.println("url :"+status.getUser().getURL());
                System.out.println("Lang :"+status.getLang());
            }
            if (statuses.size() == size)
                break;
        }catch(TwitterException e) {
            e.printStackTrace();
        }
    }
    System.out.println("Total: "+statuses.size());
}

Update : After the answer given by @AndyPiper

the my problem is every tweet that I get will be truncated or not complete. a tweets that I get will be truncated if the length of tweet more than 140 characters. I found the reference tweet_mode=extended, but I do not know how to use it. if you know something please tell me.


Solution

  • The Twitter API limits the timeline history to 3200 Tweets. To get more than that you would need to use the (commercial) premium or enterprise APIs to search for Tweets by a specific user.