【问题标题】:Python: Hashtag search with TweepyPython:使用 Tweepy 进行标签搜索
【发布时间】:2021-08-25 00:21:08
【问题描述】:

我想使用 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

>>> []

【问题讨论】:

    标签: python api twitter tweepy


    【解决方案1】:

    API.search 使用 Twitter 的 standard search API 并且不接受 date_sincedate_until 参数:

    请注意,搜索索引有 7 天的限制。换句话说,不会找到超过一周的推文。

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

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

    您将需要使用完整存档的premium search API 端点,而不是API.search_full_archive

    【讨论】:

    • 谢谢,我成功完成了完整的档案搜索!
    猜你喜欢
    • 1970-01-01
    • 2021-05-23
    • 1970-01-01
    • 2017-08-16
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    • 2018-12-17
    • 1970-01-01
    相关资源
    最近更新 更多