Is there a way to do a "not" query with language?


#1

Is there a way to format my twitter API queries to search tweets not written in a specified language? I can use “en” to see all tweets in English but how can I search tweets in any language but English?


#2

Yes. To search for English tweets containing the word Shakespeare, search for “shakespeare lang:en”. To search for non-English tweets containing the word Shakespeare, search for “shakespeare -lang:en”.


#3

Thank you very much for the reply. When I modified my TwitterAPI query from ‘lang’:‘en’ to ‘-lang’:‘en’ I still get some english results so I’ll have to play around with it to see what’s going on.


#4

I tried this request in the API Console, and it appears that search/tweets does not support negating a language.

https://api.twitter.com/1.1/search/tweets.json?q=pizza&-lang=en

Can you confirm if this is correct?


#5

That appears to be correct.


#6

Close, but not correct. This is what you need:
https://api.twitter.com/1.1/search/tweets.json?q=pizza%20-lang:en


#7

When I put this into the API Console I get back plenty of EN’s. It looks like lang is ignored.

To clarify, are you saying that when filtering for a language use lang= (with an equals) and when filtering for not a language use -lang: (with a colon)?


#8

Compare https://twitter.com/search?q=pizza%20-lang%3Aen with https://twitter.com/search?q=pizza%20lang%3Aen.

Notice how I’m including “lang:en” in the query itself, not as a separate lang= parameter, in both cases.

It’s exactly the same with the API.


#9

Thanks!


#10

Just caught that. Great job and thank you!