Search code examples
javatwittertwitter4j

how can i get English tweets only using java?


here the code

public void onStatus(Status status) {
String lang = status.getUser().getLang();
if (tweetCount < 50000) {
if (lang.equals("en")) {
storeInFile(status);
tweetCount++;
     }
    } 
}

tweets i get from all the languages. Is there a way to restrict myself to fetching tweets only in English?


Solution

  • The code you are using doesn't return the language of the tweet Why don't you try:

    status.getLang()
    

    From here:

    Interface Status

    java.lang.String getLang()

    Returns the lang of the status text if available.

    Returns:

    two-letter iso language code Since: Twitter4J 3.0.6