gpt4 book ai didi

php - 从 Twitter API 获取所有推文和重新推文

转载 作者:行者123 更新时间:2023-12-05 01:17:44 24 4
gpt4 key购买 nike

我在使用 Twitter API 时遇到了一个问题。我的问题是我无法从 Twitter 获得所有推文和转推作为响应。我已经阅读了推特上的文档 link .他们提到 此方法最多只能返回用户最近的 3,200 条推文。用户对其他状态的 native 转推都包含在此总数中,无论在请求此资源时是否将 include_rts 设置为 false。

但是当我点击 https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=xxxxx&count=968 时,我只有 198 条记录作为响应,而我有 968 条记录推文。

请帮助我了解如何从 Twitter 获取所有记录作为响应以及我必须在 URL 中传递哪些参数才能获取所有推文和转推?

请建议我更好的方法。

最佳答案

count - optional
Specifies the number of Tweets to try and retrieve, up to a maximum of 200 per distinct request. The value of count is best thought of as a limit to the number of Tweets to return because suspended or deleted content is removed after the count has been applied. We include retweets in the count, even if include_rts is not supplied. It is recommended you always send include_rts=1 when using this API method.

通过 twitter api,您可以在一个请求中获得 200 条推文。您必须发出另一个请求才能获得下一组推文。你得到 198,因为转发也算作推文。

The max_id parameter

The solution to the issue described above is to use a technique for working with streams of data called cursoring. Instead of reading a timeline relative to the top of the list (which changes frequently), an application should read the timeline relative to the IDs of Tweets it has already processed. This is achieved through the use of the max_id request parameter.

To use max_id correctly, an application’s first request to a timeline endpoint should only specify a count. When processing this and subsequent responses, keep track of the lowest ID received. This ID should be passed as the value of the max_id parameter for the next request, which will only return Tweets with IDs lower than or equal to the value of the max_id parameter.

关于php - 从 Twitter API 获取所有推文和重新推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48780885/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com