问题描述
我的代码如下:
user = api.get_user('any_user_you_like')
for status in api.user_timeline(user, count=1, trim_user=1):
status = str(status.id)
当我在自己的 Twitter 帐户上运行它时,它会毫无问题地返回我最新的推文 ID.但是,当我在拥有大量推文(例如名人)的推特帐户上运行此程序时,我收到错误消息:
When I run this on my own twitter account it returns my latest tweet ID with no issue. However when I run this on the twitter account of someone with a lot of tweets, like a celebrity I receive the error:
tweepy.error.TweepError: Twitter error response: status code = 414
看起来返回的东西太大而无法解析,但是我只要求 1 条推文,它适用于我自己的用户和我的朋友的用户,他们的推文大约为 1300 条或更少.
It looks like something is coming back too large to be parsed, however I'm only asking for 1 tweet and it works on my own user and those of my friends who have roughly 1300 tweets or less.
有什么建议,或者有没有更好的方法来获取特定用户的最后一条推文?该脚本继续将收到的推文 ID 与该用户的最后一条推文进行比较,以确定它是否是新推文,但可能有更好的方法来执行此操作.
Any suggestions, or is there a better way to get just the last tweet of a specific user? The script continues by comparing the tweet ID received to the last tweet by that user to determine if it is new, however there may be a better way to do this.
推荐答案
我解决了这个问题.api.get_user 为用户返回大量数据,这些数据不一定是他们的用户 ID 或任何相关内容.你可以完全放弃 user = api.get_user('name')
位,只做:
I solved the issue. api.get_user returns a ton of data for the user that isn't necessarily their user ID or anything relevant. You can forgo the user = api.get_user('name')
bit entirely and just do:
for status in api.user_timeline(screen_name='any_name_you_like', count=1, trimuser=1):
status = str(status.id)
这篇关于Tweepy 仅返回 414 错误检索最近推文的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!