【发布时间】:2022-01-19 02:37:39
【问题描述】:
我有一个与这个问题类似的问题 (Problem with getting user.fields from Twitter API 2.0) 但我正在使用 Tweepy。当使用 tweet_fields 发出请求时,响应只会给我默认值。在我使用 user_fields 的另一个功能中,它可以完美运行。 我遵循了本指南,特别是第 17 号 (https://dev.to/twitterdev/a-comprehensive-guide-for-using-the-twitter-api-v2-using-tweepy-in-python-15d9)
我的函数如下所示:
def get_user_tweets():
client = get_client()
tweets = client.get_users_tweets(id=get_user_id(), max_results=5)
ids = []
for tweet in tweets.data:
ids.append(str(tweet.id))
tweets_info = client.get_tweets(ids=ids, tweet_fields=["public_metrics"])
print(tweets_info)
这是我的回复(来自 elonmusk 的最后一条推文)也没有错误代码或其他任何内容
Response(data=[<Tweet id=1471419792770973699 text=@WholeMarsBlog I came to the US with no money & graduated with over $100k in debt, despite scholarships & working 2 jobs while at school>, <Tweet id=1471399837753135108 text=@TeslaOwnersEBay @PPathole @ScottAdamsSays @johniadarola @SenWarren It’s complicated, but hopefully out next quarter, along with Witcher. Lot of internal debate as to whether we should be putting effort towards generalized gaming emulation vs making individual games work well.>, <Tweet id=1471393851843792896 text=@PPathole @ScottAdamsSays @johniadarola @SenWarren Yeah!>, <Tweet id=1471338213549744130 text=link>, <Tweet id=1471325148435394566 text=@24_7TeslaNews @Tesla ❤️>], includes={}, errors=[], meta={})
【问题讨论】:
-
注意缩进(方法声明后4个空格)。它打印什么?或者控制台上是否有任何错误 - 请分享这个。
-
如果您遵循问题的答案会发生什么:将参数
expansions = ['author_id']添加到get_tweets的调用中? -
谢谢我编辑了我的问题。如果我添加 expands=["author_id"] 它只会给我有关用户的信息,但仍然不是公共指标。