I’m trying to fetch tweets which contain a certain word(s) and display them on my website in the order of their publish datetimes.

The url I’m using for the standard search API looks like this:

https://api.twitter.com/1.1/search/tweets.json?q=nature&result_type=recent&count=100&tweet_mode=extended

But there might be some accounts whose tweets are spammy or are of little to no use to me. Is it possible to exclude their tweets during the searching? I couldn’t find a parameter for doing that in the standard search API’s documentation.

Although I can remove their tweets from the results returned by Twitter, that would make the result count less than 100 (my ideal result count).

You may have been looking for this page: Using standard search | Docs | Twitter Developer Platform

use the - operator to negate or exclude something. eg: nature -from:NatGeo nature tweets but excluding results from @NatGeo

I find it’s useful to use the https://twitter.com/search-advanced advanced search to build a query string i can take from the URL

2 Likes

Thanks for the resources. So according the advanced search’s format, I guess the following url excludes tweets from FirstAccount and SecondAccount:

https://api.twitter.com/1.1/search/tweets.json?q=nature%20%28-from%3AFirstAccount%20-from%3ASecondAccount%29

The value of the q parameter above is the encoded version of nature (-from:FirstAccount -from:SecondAccount).

Would you please help check if it’s correct?

I don’t think you need the parentheses () - just add the two negative account parameters to the main query.

1 Like

@andypiper Thanks. I will go with the following url then:

https://api.twitter.com/1.1/search/tweets.json?q=nature%20-from%3AFirstAccount%20-from%3ASecondAccount

Thank you all again! :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.