views:

141

answers:

2

Hi All,

I am working with a java Twitter app (using Twitter4J api). I have created the app and can view the current users timeline, user's profiles, etc..

However, when using the app it seems to quite quickly exceed the 150 requests an hour rate limit set on Twitter clients (i know developers can increase this to 350 on given accounts, but that would not resolve for other users).

Surely this is not affecting all clients, any ideas as to how to get around this?

Does anyone know what counts as a request? For example, when i view a user's profile, i load the User object (twitter4j) and then get the screenname, username, user description, user status, etc to put into a JSON object - would this be a single call to get the object or would it several to include all the user.get... calls?

Thanks in advance

+2  A: 

You really do need to keep track what your current request count is when dealing with Twitter.

However, twitter does not seem to drop the count for 304 Not Modified (at least it didn't the last time I dealt with it), so make sure there isn't something breaking your normal use of HTTP caching, and your practical request per hour goes up.

Note that twitter suffers from a bug in mod_gzip on apache where the e-tag is mal-formed in changing it to reflect that the content-encoding is different to that of the non-gzipped entity (this is the Right Thing to do, there's just a bug in the implementation). Because of this, accepting gzipped content from twitter means it'll never send a 304, which increases your request count, and in many cases undermines the efficiency gains of using gzip.

Hence, if you are accepting gzip (your web-library may do so by default, see what you can see with a tool like Fiddler, I'm a .NET guy with only a little Java knowledge, answering at the level of how twitter deals with HTTP so I don't know the details of Java web libraries), try turning that off, and see if it improve things.

Jon Hanna
Thanks for the advice - I will investigate the HTTP caching and make sure that i am caching the calls appropriately.I have managed to identify a big part of the problem was that as I was making the list of JSON objects (for example, the recent timeline) I was fetching all data that might be needed further on (e.g. for each update on the timeline i was fetching all the users info such as name/description/num followers etc). I have changed it so it only fetches the basic data for the list and then "lazily" fetches further data when required.Thanks again!
rhinds
FWIW, I reported the bug with the interaction between 304 and gzip to twitter. Since it's an apache bug, it's probably not going to be fixed at their level. The apache bug was already known at apache when I discovered this in twitter.
Jon Hanna
A: 

Almost every type of read from Twitter's servers (i.e. anything that calls HTTP GET) counts as a request. Getting user timelines, retweets, direct messages, getting user data all count as 1 request each. Pretty much the only Twitter API call that reads from the server without counting against your API limit is checking to see the rate limit status.