Search code examples
twittertwitter4j

How to restrict the language of results in Twitter4j to english?


I tried using the setLang(String lang) i.e; -->setLang("en") and lang(String lang) i.e; lang("en") methods of the Query class. But they are not working.

Also if I want to use multiple keywords in my search query and should restrict the results to tweets containing ALL keywords, what should I do ?


Solution

  • Just palyed with dev console and made search api call like this (search for tweets "stackoverflow" in russian):

    https://api.twitter.com/1.1/search/tweets.json?q=stackoverflow&lang=ru
    

    ... and it worked just fine. Less likely but this might be a bug in twitter4j. Try to debug it and see what actual call to api is made. This should give you some clues.

    About the second question. See section "Search Operators" from this doc. what you want is default behavior, so, simply list your keywords with spaces between them and this should do the trick.