在Tweepy中使用search_full_archive

问题描述

有人知道如何在tweepy模块中使用search_full_archive功能吗?我使用了与常规搜索类似的光标功能,但没有用。

import tweepy as tw

api_key = '***'
api_secret_key = '***'
access_token = '***'
access_token_secret = '***'

#Authenticate
auth = tw.OAuthHandler(api_key,api_secret_key)
auth.set_access_token(access_token,access_token_secret)
api = tw.API(auth)

# search tweets
def get_tweets_full(hashtag):
    tweetObj_full = tw.Cursor(
        self.api.search_full_archive,environment_name = 'VolcanicDisaster',# Dev environment label from twitter developer dashboard
        query = hashtag
    )
     return tweetObj

get_tweets(hashtag = '#kilauea')

我收到一条错误消息,指出“ API对象没有属性search_full_archive”。但是,如果我使用常规搜索方法api.search(带有参数q)而不是api.search_full_archive,则可以正常工作。我想回顾2年前的推文,并要求使用api_full_search,想知道是否有人知道如何使用此功能? 我已经使用twitter API设法设置了高级帐户(沙盒版本-免费),但是当我输入dir(api)时,在方法的输出列表中没有看到search_full_archive方法。

解决方法

首先,完整归档功能仅在Premium / Enterprice API上可用。但是,您也可以在有限的时间内免费将您的标准开发者帐户免费升级为高级版。

第二,在3.10.0版本中,支持完整存档功能!!!但是您需要更新tweepy。当前无法使用pip更新,因此您需要更新为pip install --upgrade git+https://github.com/tweepy/tweepy@master。然后您的API就可以使用了,

最后,您需要使用documentation of tweepy重新描述您的API。这是tweepy API对象的2个示例;

search_words ='**KEYWORD/HASHTAG/USERNAME**'
date_since = "13-08-2020"
date_since_pro = "202008130000"
numTweets = 100

# standart search
tweets = tweepy.Cursor(api.search,q=search_words,since=date_since).items(numTweets)

# premium search
tweets=tweepy.Cursor(api.search_full_archive,environment_name='**ENV NAME FROM API**',query=search_words,fromDate=date_since_pro).items(numTweets)

如您所见,需要使用 search_full_archive 功能更改日期格式。

,

“搜索完整存档”功能仅在Premium和Enterprise Api访问中可用。免费的API用户只能访问最近的推文(最近7天)。

参考:https://developer.twitter.com/en/docs/twitter-api/v1/tweets/search/overview

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...