Tweepy returns 414 error retrieving status of only most recent tweet

一笑奈何 提交于 2019-12-12 05:04:19

问题


My code looks like:

user = api.get_user('any_user_you_like')
for status in api.user_timeline(user, count=1, trim_user=1):
    status = str(status.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

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.

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.


回答1:


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)


来源:https://stackoverflow.com/questions/47341988/tweepy-returns-414-error-retrieving-status-of-only-most-recent-tweet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!