I am trying to extract information from Twitter's API using Tweepy. 90% of the code works fine, but when I try to get the followers_count from each tweet, I run into an error.
The code I am using is:
# Running only on handle returns a dataframe
tweets = api.user_timeline(user_id=user_id, count=number_tweets, tweet_mode="extended")
print("Number of tweets extracted: {}.
".format(len(tweets)))
data = pd.DataFrame(data=[tweet.full_text for tweet in tweets], columns= ["Text"])
data["Tweet length"] = np.array([len(tweet.full_text) for tweet in tweets])
data["Tweet ID"] = np.array([tweet.id for tweet in tweets])
data["Tweet Date"] = np.array([tweet.created_at for tweet in tweets])
data["Tweet source"] = np.array([tweet.source for tweet in tweets])
data["Tweet likes"] = np.array([tweet.favorite_count for tweet in tweets])
data["Tweet retweets"] = np.array([tweet.retweet_count for tweet in tweets])
# Line to be added here #
data = data.sort_values(by="Tweet Date", ascending = False)
When I got to add in the following line:
data["User followers"] = np.array([tweet.followers_count for tweet in tweets])
The error message is:
AttributeError: 'Status' object has no attribute 'followers_count'
question from:
https://stackoverflow.com/questions/65845316/attributeerror-using-tweepy-and-twitter-api 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…