kane.zorfy
kane.zorfy

Reputation: 1040

How to use AND and OR operands at the same time in Twitter API?

I'm trying to retrieve the tweets which contain words like wall clock, wall paper, wall stickers using tweepy filter option. I know that 'space' means AND and ',' means OR.

Official doc I've referred: https://dev.twitter.com/streaming/overview/request-parameters#track

In the docs example given 'twitter api,twitter streaming' should get the following tweets.

1. The Twitter API is awesome
2. The twitter streaming service is fast
3. Twitter has a streaming API

Is there any way to combine both of these operands.

For eg: "twitter api,streaming" should retrieve all the above tweets.

I tried this approach

class StdOutListener(StreamListener):

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

    def on_error(self, status):
        print status


l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)

stream.filter(track=['stream.filter(track=['twitter api,streaming'])'])

Its only getting the tweets which either contain streaming or twitter api. But not the way I wanted.

Upvotes: 0

Views: 100

Answers (1)

Leb
Leb

Reputation: 15953

You simply need to have twitter OR api OR streaming without the comma. This method will give you all 3 that you listed.

Now if you want twitter api or twitter streaming like that then do the following: "twitter api" OR "twitter streaming". This will give you 1 and 2 from your list, not 3.

For more information check out Query Operators

To be clear about the and and or, and does not have to be explicitly specified as far as twitter is concerned for the following reason:

watching now -- containing both “watching” and “now”. This is the default operator.

Please note that this is different from using "watching now" which implies "watching" has to be immediately followed by the word "now".

However, or does have to be specified:

love OR hate -- containing either “love” or “hate” (or both).

Upvotes: 0

Related Questions