Python:使用Tweepy进行哈希标签搜索



我想用Tweepy获得#MeTooMen的Tweets。就我搜索推特而言,有很多推文使用这个标签,但当我尝试用推文获取这些推文时,我得到了0个结果。你知道我能做些什么来改进这个代码吗?

import os
import tweepy as tw
import pandas as pd
api_key = '*'
api_secret_key = '*'
access_token = '*'
access_token_secret = '*'
auth = tw.OAuthHandler(api_key, api_secret_key)
auth.set_access_token(access_token, access_token_secret)
api = tw.API(auth, wait_on_rate_limit=True)
# Define the search term and the date_since date as variables
search_words = "#metoomen"
date_since = "2017-10-17"
date_until = "2018-01-31"

tweets = tw.Cursor(api.search,
q = search_words,
lang = "en",
since = date_since,
until = date_until).items(5)
users_locs = [[tweet.user.screen_name, tweet.user.location, tweet.text] for tweet in tweets]
users_locs
>>> []

API.search使用Twitter的标准搜索API,不接受date_sincedate_until参数:

请记住,搜索索引有7天的限制。换言之,超过一周的约会不会出现推特。

https://developer.twitter.com/en/docs/twitter-api/v1/tweets/search/guides/standard-operators还说:

[It]不是所有推文的完整索引,而是最近推文的索引。该指数包括6-9天的推文。

您需要使用带有API.search_full_archive的完整体系结构高级搜索API端点。

最新更新