Search code examples
pythontwittertweepy

Tweepy code does not work to collect Tweets -- Python


I am attempting to collect tweets with tweepy in python. However, the cursor function does not appear to work. The error says that 'API' object has no attribute 'search' .

Code:

from config import *
import tweepy
import datetime

access_token="ACCESS TOKEN HERE"
access_token_secret="ACCESS TOKEN SECRET HERE"
consumer_key="CONSUMER KEY HERE"
consumer_secret="CONSUMER KEY SECRET HERE"
auth= tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_token_secret)

api = tweepy.API(auth,wait_on_rate_limit=True)

today = datetime.date.today()
yesterday= today - datetime.timedelta(days=1)
today, yesterday

tweets_list = tweepy.Cursor(tweepy.api.search, q="#Covid-19 since:" + str(yesterday)+ " 
until:" + str(today),tweet_mode='extended', lang='it').items()

Solution

  • If you are using Tweepy v4 this has changed to API.search_tweets() https://docs.tweepy.org/en/latest/changelog.html#version-4-0-0