我试图根据特定关键字从特定用户提取推文,但遇到了一些困难。我收到错误消息:“用户”对象不可迭代。
#Import the libraries
import tweepy
from textblob import TextBlob
from wordcloud import WordCloud
import pandas as pd
import numpy as np
import re
import sys
import csv
import string
import matplotlib.pyplot as plt
api_key = "JISLFz4iz1WRyG1sPtg6Iuhob"
api_key_secret = ""
access_token = "1372812318900252672-fVqTH8B6TvrexgYyrSF4gSu1oF4SEl"
access_token_secret = ""
auth_handler = tweepy.OAuthHandler(consumer_key=api_key, consumer_secret=api_key_secret)
auth_handler.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth_handler,wait_on_rate_limit=True)
user = api.get_user("NewtoCryto")
print("User details:")
print(user.name)
print(user.description)
for tweets in user:
for tweet in api.search(q="defi", lang="en", rpp=10):
print(f"{tweet.user.name}:{tweet.text}")