Search code examples
javatwitterstreamingtwitter4j

Twitter Streaming API : Tracking changing keywords


I would like to track changing keywords on the streaming API (from a java client) without losing tweets in the process - for instance, if I am tracking 'keyword1,keyword2' at this moment, a moment later, I would like to configure the streaming api to track say.. 'keyword1,keyword2,keyword3'. This adds a few problems to the context:

  1. Keyword3 has been newly added, so this would require me to drop the existing streaming connection, and reopen one with the new keywords.
  2. Reconnect would mean that I would lose some tweets on keyword1,keyword2 - I understand that I can use the count keyword to retrieve lost tweets (but this would require elevated access).

So, here are my questions in this context:

  1. Is it possible to track new keywords without reconnecting? Possibly open a new streaming connection (don't think twitter allows that from same IP?), start tracking on the new connection and kill the old connection?
  2. If I do not have elevated access, how do I go about retrieving lost tweets?
  3. Say, I have elevated access, Would I receive lost tweets for 'keyword1,keyword2' or would Twitter fail to give me lost tweets coz the keywords have had changed?

Solution

  • I believe the docs say you should open a new connection with this new keyword, and as soon as that is connected disconnect the previous one. If this is done correctly you shouldn't lose any tweets in the process.