Search code examples
javatwitter4j

How do I perform a twitter search using advanced parameters


http://twitter.com/search-advanced

I would like to perform search queries which mimic the above screen (e.g. How do I find all tweets which satisfy "none of the words" criteria or just #hashtags criteria). Would it be possible to mix-n- match some of these fields using twitter4j, currently I am able to perform only simple searches using keywords.


Solution

  • If you fill out some of the advanced search page and actually do the search, it'll populate a search box with the constructed query string. For example, if I set it up as follows:

    • All of these words: word1 word2
    • Any of these words: word3 word4
    • None of these words: word5
    • From these accounts: user1 user2
    • Mentioning these accounts: user3

    "word1 word2 word3 OR word4 -word5 from:user1 OR from:user2 @user3"

    Then you just stick that string into your created query.

    Query query = new Query("word1 word2 word3 OR word4 -word5 from:user1 OR from:user2 @user3");