如何解决Python:使用 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
使用 Twitter 的 standard search API 并且不接受 date_since
或 date_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
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。