我在使用friends_count Tweepy V2 API调用获取search_all_tweets和V2时遇到了问题。
GeeksForGeeks将friends_count和favorites_count列为属性( https://www.geeksforgeeks.org/python-user-object-in-tweepy/)。不幸的是,在最后两行代码中,我得到了一个属性错误raise AttributeError from None。
user.public_metrics仅由followers_count、following_count、tweet_count和listed_count组成。
user.entities由外来的url数据组成。
代码如下:
client = tweepy.Client(bearer_token=config.BEARER_TOKEN, consumer_key=
config.CONSUMER_KEY,consumer_secret= config.CONSUMER_SECRET,access_token=
config.ACCESS_TOKEN,access_token_secret= config.ACCESS_TOKEN_SECRET)
for response in tweepy.Paginator(client.search_all_tweets, query=s,
tweet_fields=['context_annotations','created_at', 'public_metrics','author_id', 'lang', 'geo', 'entities'],
user_fields=['username','entities','public_metrics','location','verified','description'],
max_results=100, expansions='author_id'):
for user in response.includes["users"]:
print(user.public_metrics)
print(user.entities)
print(user.friends_count)
print(user.favorites_count)发布于 2022-07-15 07:41:18
GeeksForGeeks列出的字段是Twitter V1 API中的用户字段。
不幸的是,使用Twitter V2 API无法获得用户的数量。您可以尝试获取他所有的赞,并计算返回的Tweet的总数,但只有当用户只有几个赞(并且这将消耗您的每月Tweet上限)时,这才能工作。
而好友是之前的名字,所以friends_count在Twitter V2 API中的等价物是following_count。如果您正在寻找互斥,您必须得到完整的追随者列表和用户的后续完整列表,并计算公共元素的数量。
最后,我建议您使用Twitter文档(这里用于用户对象)。
https://stackoverflow.com/questions/72986305
复制相似问题