Include filtering-criteria in Streaming API

python

#1

Hi,

According to Twitter’s documentation I can add -filter:links in a search term to exclude links. This clearly works in the search portal of Twitter However, I would like to know if I can also include it in my python-script that uses the Streaming API. The following search output differs from the output of my Python script if I compare them

Twitter website:

https://twitter.com/search?f=tweets&q=Russia%20OR%20America%20OR%20England%20-filter%3Alinks&src=typd

Python:

search_terms = ['Russia', 'America', 'England', ' AND -filter:links']

class StdOutListener(StreamListener):

def on_data(self, data):
    print(data)
    return True

def on_error(self, status):
    print(status)
    
if __name__ == "__main__":
listener =  StdOutListener()
auth = OAuthHandler(USER_KEY, USER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)

stream = Stream(auth, listener)
stream.filter(languages=['en'], track=search_terms)

I would like the stream.filter function to do the following

stream.filter(languages=['en'], track= Russia OR America OR England AND -filter:links

#2

Hi - My colleague just responded to a similar question on StackOverflow.

The -filter: syntax doesn’t work with the Streaming API. You can find the full list of available operators here. As it stands, your request is basically filtering for 4 keywords, including “AND -filter:links” which is unlikely to return anything.

In order to exclude links using the -filter: search term with a streaming API, you would have to use the enterprise PowerTrack API. However, note that this is a commercial API.


#3