I'm trying to get the location of tweets I've collected using the package tweepy
:
import tweepy as tw
consumer = ...
consumer_secret = ...
access_token = ...
access_token_secret = ...
auth = tw.OAuthHandler(consumer, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tw.API(auth, wait_on_rate_limit=True)
search_words = "delante"
date_since = "2022-01-03"
tweets = tw.Cursor(api.search_tweets,
q = search_words,
lang = "es",
since = date_since)
loc = []
for tweet in tweets:
loc.append(tweet.user.location)
But I get this error:
'Cursor' object is not iterable
The output of type(tweets)
is tweepy.cursor.Cursor
.
What is it that I'm missing?
The
tweepy.Cursor
object is indeed not iterable. Calltweets.items()
to get an iterator over the individual tweets, ortweets.pages()
to get an iterator over pages worth of tweets.Reference