Search code examples
twittertweepydata-science

How to perform a boolean search using the Twitter search API through tweepy


new_tweets = api.search(q=searchQuery, count=tweetsPerQry)

How do i perform a AND , OR, NOT serach for searchQuery ?


Solution

  • Tweepy's api.search method send the q parameter directly to Standard search API (/search/tweets.json) of Twitter's REST API endpoint.

    So you can check which parameter can be accepted by this endpoint in "Standard search operators" section of this document:

    Therefore, we can search tweets including stackoverflow about python or ruby without tweepy by using the search query like this: "stackoverflow (python OR ruby) -tweepy".

    Basically, these search operators are just the same as ones we can use in the Twitter's official search textbox.