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?
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”.
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.
I tried this request in the API Console, and it appears that search/tweets does not support negating a language.
search/tweets
https://api.twitter.com/1.1/search/tweets.json?q=pizza&-lang=en
Can you confirm if this is correct?
That appears to be correct.
Close, but not correct. This is what you need: https://api.twitter.com/1.1/search/tweets.json?q=pizza%20-lang:en
When I put this into the API Console I get back plenty of EN’s. It looks like lang is ignored.
lang
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)?
lang=
-lang:
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.
Thanks!
Just caught that. Great job and thank you!