4
votes

I'm using Twitter4J to get the tweets of given user. However sometimes the tweet text get shortened with ... at the end and t.co link with full text is provided. Someone have an idea what I have to do to get the full text directly within Twitter4J?

My Code (shortened):

ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true.setOAuthConsumerKey("xyz")
                .setOAuthConsumerSecret("xyz")
                .setOAuthAccessToken("xyz")
                .setOAuthAccessTokenSecret("xyz");

        Twitter twitter = new TwitterFactory(cb.build()).getInstance();
        List<Status> status = new ArrayList();
        Paging page = new Paging(1, 100);
        status.addAll(twitter.getUserTimeline("NASA", page));

        for (Status tweet : statuses) {
            System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
        }

E.g. Latest tweet of NASA full length:

There were 3 more for Thanksgiving dinner aboard the @Space_Station, with the arrival this week of @AstroPeggy and her colleagues.

What Twitter4J delivers:

There were 3 more for Thanksgiving dinner aboard the @Space_Station, with the arrival this week of @AstroPeggy and… https ://t . co/zw6QrudPCu

1

1 Answers

4
votes

I solved this problem by activating extended mode when setting up ConfigurationBuilder:

ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setTweetModeExtended(true); //Plus other options

Twitter4J now returns a full message. Be warned though that by activating this mode the messages returned by Twitter are now allowed to exceed 140 characters. Here are official docs on extended mode.