tags:

views:

375

answers:

2

Hi folks,

I have a list of usernames on Twitter whose profiles are public. I wish to get "all the tweets" they have posted from the day they formed their profile. I checked Twitter4J examples http://github.com/yusuke/twitter4j/blob/master/twitter4j-examples/src/main/java/twitter4j/examples/GetTimelines.java . According to the Twitter API documentation, only the 20 most recent tweets are returned. Is there anyway I could perform my task?

A: 

If you read through http://dev.twitter.com/doc/get/statuses/user_timeline, you can retrieve up to 200 tweets at a time if you specify "count=200" in your API request.

You can also use "page=x" to get different paginated results; you could keep doing this until you've retrieved every tweet the user has posted.

I'm not sure how your Java application would create this, but your requests would probably look like:

http://api.twitter.com/1/statuses/user_timeline.xml?id=SomeUsername&count=200&page=1
http://api.twitter.com/1/statuses/user_timeline.xml?id=SomeUsername&count=200&page=2
http://api.twitter.com/1/statuses/user_timeline.xml?id=SomeUsername&count=200&page=3

... etc.

Keep in mind that these requests are rate-limited so you'd need to be careful not to exceed the limit.

Chris
A: 

To use Twitter4J to get all posts from a user you'll have to make your request over multiple pages..

Below code based off an example from http://github.com/yusuke/twitter4j/blob/master/twitter4j-examples/src/main/java/twitter4j/examples/GetTimelines.java

Twitter unauthenticatedTwitter = new TwitterFactory().getInstance();
//First param of Paging() is the page number, second is the number per page (this is capped around 200 I think.
Paging paging = new Paging(1, 100);
List<Status> statuses = unauthenticatedTwitter.getUserTimeline("google",paging);

Just loop and keep grabbing new pages until there are no new posts should work.

Tyler
Tyler,Thanks for the response!However, when I run the same code as said above I get this error <code>"[Thu Jun 03 01:29:51 IST 2010]Using class twitter4j.internal.logging.StdOutLoggerFactory as logging factory.[Thu Jun 03 01:29:51 IST 2010]Use twitter4j.internal.http.HttpClientImpl as HttpClient implementation.Failed:Connection refused: connect"</code>I am able to get the public timeline using the getPublicTimeLine() function.
Denzil
I tried the same using authentication twitter instance of my personal ID which is also public, btw.PS: I am sorry for posting the error in such unformatted format. I have tried all HTML tags including <code> and <blockquote> tags.
Denzil
You shouldn't have to authenticate to do this, are you not able to use the code above to get the public timeline of google or your own page? What are you using for paging? Could you try with just "username" as the only parameter to getUserTimeline()
Tyler
Tyler, Thanks for the response. I am able to retrieve the tweets today! The API is very erratic in it's output as I'm testing the same since the past two days. In any case, The next problem though is that the code works ONLY for the paging parameters 1,100. I tried for different public usernames but in vain. The API limitation is 3200 {16,200} with a count of 200 per request as mentioned on the website. However, I am unable to avail the functionality.
Denzil