Python:使用 Tweepy 进行标签搜索

Python: Hashtag search with Tweepy

我想使用 Tweepy 获取带有#MeTooMen 的推文。 就我搜索 Twitter 而言,有很多推文使用此主题标签,但当我尝试使用 Tweepy 获取这些推文时,结果为 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 uses Twitter's standard search API 并且不接受 date_sincedate_until 参数:

Keep in mind that the search index has a 7-day limit. In other words, no tweets will be found for a date older than one week.

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

[It] is not a complete index of all Tweets, but instead an index of recent Tweets. The index includes between 6-9 days of Tweets.

您需要使用完整存档 premium search API endpoint, with API.search_full_archive