'Tweepy AttributeError: 'API' object has no attribute 'search'
I'm trying to get tweets using tweepy but I am running into this error:
AttributeError: 'API' object has no attribute 'search'
Code:
import tweepy
# Authentication
consumerKey = "Type your consumer key here"
consumerSecret = "Type your consumer secret here"
accessToken = "Type your accedd token here"
accessTokenSecret = "Type your access token secret here"
auth = tweepy.OAuthHandler(consumerKey, consumerSecret)
auth.set_access_token(accessToken, accessTokenSecret)
api = tweepy.API(auth)
#Sentiment Analysis
def percentage(part,whole):
return 100 * float(part)/float(whole)
keyword = input("Please enter keyword or hashtag to search: ")
noOfTweet = int(input ("Please enter how many tweets to analyze: "))
tweets = tweepy.Cursor(api.search, q=keyword).items(noOfTweet)
How can I fix this?
Solution 1:[1]
Use:
tweets = tweepy.Cursor(api.search(q=keyword)).items(noOfTweet)
Solution 2:[2]
use api.search_tweets instead of api.search
tweepy v.4.0.0 has changed it..
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |
