[英]Find old tweets using Python tweepy
Python 3.9.5蟒蛇 3.9.5
tweepy == 4.10.0 tweepy == 4.10.0
I am trying to get old tweets using tweepy but it does not work well (shows 0 result).我正在尝试使用 tweepy 获取旧推文,但效果不佳(显示 0 结果)。 Here's what I tried.
这是我尝试过的。
BEARER_TOKEN = "My Token"
DATE_STA = "2020-01-01T00:00:01Z"
DATE_END = "2020-06-01T23:59:59Z"
client = tweepy.Client(BEARER_TOKEN, wait_on_rate_limit=True)
user = client.get_user(username="hellopolicy")
res = client.get_users_tweets(
user.data.id,
end_time = DATE_END,
start_time = DATE_STA,
max_results = 100,
tweet_fields = ["text", "created_at", "conversation_id", "public_metrics"]
)
print(res)
# Response(data=None, includes={}, errors=[], meta={'result_count': 0})
But if I search it manually from the web with a query (from:hellopolicy since:2020-01-01 until:2020-06-01), I can see many tweets during that period.但是,如果我使用查询(from:hellopolicy since:2020-01-01 until:2020-06-01)从网络上手动搜索它,我可以在此期间看到许多推文。
This behavior depends on target IDs.此行为取决于目标 ID。 Most of them showed all results correctly but the others (1-2 out of 10) showed only a couple of weeks or nothing.
他们中的大多数人正确地显示了所有结果,但其他人(10 人中有 1 人)只显示了几周或什么也没有。 Numbers of tweets in the IDs were not the matter.
ID 中的推文数量无关紧要。
Why This happens and how can I get all the tweets?为什么会发生这种情况,我怎样才能获得所有推文?
You may not have any results returned due to the limited range of dates that you may scrape with the standard API .由于您可以使用标准 API抓取的日期范围有限,您可能不会返回任何结果。 As quoted:
如引述:
The Twitter Search API searches against a sampling of recent Tweets published in the past 7 days.
Twitter 搜索 API 根据过去 7 天内发布的最新推文样本进行搜索。
I have a script that may be useful for scraping older tweets on my GitHub to circumvent this issue.我有一个脚本可能有助于在我的GitHub 上抓取旧推文以规避此问题。 Hope it helps.
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.