Twitter user_timeline 没有返回足够的推文 [英] Twitter user_timeline not returning enough tweets

查看:28
本文介绍了Twitter user_timeline 没有返回足够的推文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在 python 中使用 GET statuses/user_timeline twitter API 来检索推文,它在 docs 此方法最多只能返回用户最近的 3,200 条推文 但是当我运行它时,它只返回 100-150.

I'm currently using the GET statuses/user_timeline twitter API in python to retrieve tweets, It says in the docs This method can only return up to 3,200 of a user’s most recent Tweets however when i run it, it only returns 100-150.

如何让它返回比现在更多的推文?

How do i get it to return more tweets than it is already?

提前致谢

推荐答案

您必须编写代码来处理时间线.Twitter 的 使用时间线文档 有讨论Twitter 时间线的工作方式和原因.

You'll have to write code to work with timelines. Twitter's Working with timelines documentation has a discussion of how and why Twitter timelines work the way they do.

本质上,将您的 count 设置为最大数量 (200) 并使用 since_idmax_id 来管理阅读每个页面.或者,您可以使用现有的库来简化任务.这是一个使用 tweepy 库的示例.

Essentially, set your count to the maximum amount (200) and use since_id and max_id to manage reading each page. Alternatively, you can use an existing library to make the task much easier. Here's an example, using the tweepy library.

consumer_key = "<your consumer_key>"
consumer_secret = "<your consumer_secret>"
access_token = "<your access_token>"
access_token_secret = "<your access_token_secret>"

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

for status in tweepy.Cursor(api.user_timeline, "JoeMayo").items():
    print('status_id: {}, text: {}'.format(status.id, status.text.encode('utf-8')))

这篇关于Twitter user_timeline 没有返回足够的推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆