Search code examples
javatwittertwitter4j

Search twitter by language


In twitter by using lang operator you can search for retrieving tweets from a particular language: For example, the following search will return tweets only in english:

https://twitter.com/search?q=lang:en

Is there a way to achieve this using twitter api, especially using twitter4j. I know there is a language attribute for search but it also requires at least one keyword to make a search, I would like to search by a particular language without giving any keyword query. The following command in java driver returns the following error:

Query searchQuery = new Query() //
                        .count(resultsPerPage) //
                        .since(since)//
                        .lang("en");

400:The request was invalid. An accompanying error message will explain why. This is the status code will be returned during version 1.0 rate limiting(https://dev.twitter.com/pages/rate-limiting). In API v1.1, a request without authentication is considered invalid and you will get this response.
message - Query parameters are missing
code - 25

Cheers


Solution

  • You must pass the same do you use in the twitter search, your query will be like:

    new Query("lang:en")