singrass
singrass

Reputation: 73

How can I use tweepy without a filter

I'm new to the tweepy library. I am able to capture a twitter stream if I use a filter like the one shown below, looking for tweets containing the word snow in the text field.

import tweepy
ckey = ''
csecret = ''
atoken = ''
asecret = ''
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=["snow"])

However, I don't know how to capture all tweets without doing any filtering. If I leave off the last line of the above code, the program runs, but I don't get any tweets. If I change the track parameter to track=[] or track=[""], I receive an error code of 406 from the Twitter API.

I am using Python 3.4.2.

Upvotes: 5

Views: 3969

Answers (3)

Aditya Saxena
Aditya Saxena

Reputation: 74

You can use twitterStream.sample() as the last line for that. It will fetch all the tweets for you.

Upvotes: 4

Prayas Jain
Prayas Jain

Reputation: 55

Dont do a search by location. It would limit out those tweets which dont have geolocation enabled. What I suggest is to use stream.sample() instead. IT doesnt have any necessary parameters. See tweepy docs for more info.

Upvotes: 2

teknoboy
teknoboy

Reputation: 177

the streaming API can only be used with at least one predicate parameter, as specified in the twitter documentation.
luckily, there's also a locations parameter, and you can pass the value [-180,-90,180,90] to get tweets from every point on earth.

so, in your snippet above, the last line should be:
twitterStream.filter(locations=[-180,-90,180,90])

the only filtering you'll get is that the user must not have turned the geotagging off.

Upvotes: 0

Related Questions