Search code examples
javatwitteroauthtwitter4j

How to use Java and Twitter API to get tweets sent by given Twitter ID?


I want to use java and Twitter API to collect Twitter data for researching, especially to collect tweets sent by a given Twitter ID.
Now I can only collect my own tweets by using Twitter4j and OAuth setting. How could I get others tweets if I could not get their OAuth?


Solution

  • The method you're looking for is: getUserTimeline(java.lang.String screenName) or: getUserTimeline(long userId)

    This will give you the latest 20 Tweets of the required user. So your code should look something like this:

    Twitter twitterConnection = getConnection(); //I assume you already know how to init a connection
    ResponseList<Status> results = twitterConnection.getUserTimeline("justinbieber");