Search code examples
twitter4j

How to get other user's mention timeline of twitter with twitter4j api?


I'm struggling to get other user's mention timeline with twitter4j api. I could figure out that it's possible only to get other user's UserTimeline. It seems that there is no way to get other user's mention timeline (I found that here - lookup "Interface TimelinesResources")

Is there way to get other user's mention timeline ???


Solution

  • You can get the MentionsTimeline using getMentionsTimeline() method of TimelineResources as a link you mentioned with some limitations of number of tweets returned.

    Find below example of the example which will give you MentionsTimeline.

    Twitter twitter = new TwitterFactory().getInstance();
    try {
           User user = twitter.verifyCredentials();
           List<Status> statuses = twitter.getMentionsTimeline();
           System.out.println("Showing @" + user.getScreenName() + "'s mentions.");
           for (Status status : statuses) {
               System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
           }
    } catch (TwitterException te) {
           te.printStackTrace();
           System.out.println("Failed to get timeline: " + te.getMessage());
           System.exit(-1);
    }