Tweepy search_full_archive() 缺少 2 个必需的位置参数:“label”和“query”

问题描述

我正在使用 Tweepy 3.10.0 一次收集包含特定关键字和主题标签的推文。我最近从标准开发者帐户升级到高级帐户以访问完整档案。我知道这将“搜索功能更改为“search_full_archive”并更改了其他一些小的语法内容。我以为我做了正确的更改,但我仍然收到此错误。我已经查看了 Developer API 参考。

consumer_key = '****'
consumer_secret = '****'
access_token = '****'
access_token_secret = '****'

auth = tweepy.OAuthHandler(consumer_key,consumer_secret)

auth.set_access_token(access_token,access_token_secret)

api = tweepy.API(auth,wait_on_rate_limit=True)

def get_tweets_withHashTags(query,startdate,enddate,count = 300):
    tweets_hlist= []
    tweets_list= []
    qt=str(query) 
    for page in tweepy.Cursor(api.search_full_archive,environment_name='FullArchive',q=qt,fromDate=startdate,toDate=enddate,count=300,tweet_mode='extended').pages(100):
      count = len(page)
      print( "Count of tweets in each page for  " + str(qt) + " : " +  str(count))
      for value in page:
        hashList = value._json["entities"]["hashtags"]
        flag = 0
        for tag in hashList:
            if qt.lower() in tag["text"].lower():
                flag = 1

        if flag==1:
          tweets_hlist.append(value._json)
        tweets_list.append(value._json)

    print("tweets_hash_"+ query +": " + str(len(tweets_hlist)))
    print("tweets_"+ query +": " + str(len(tweets_list)))
    
    with open("/Users/Victor/Documents/tweetCollection/data/"+startdate +"/" + "query1_hash_" + str(startdate)+ "_" + str(enddate) + "_" +query+'.json','w') as outfile:
      json.dump(tweets_hlist,outfile,indent = 2)

    with open("/Users/Victor/Documents/tweetCollection/data/"+startdate +"/"+"query1_Contains_" + str(startdate)+ "_" + str(enddate) + "_" +query+'.json','w') as outfile:
      json.dump(tweets_list,indent = 2)
    return len(tweets_list)

query = ["KeyWord1","KeyWord2","KeyWord3",etc.]

for value in query:
  get_tweets_withHashTags(value,"2020-04-21","2020-04-22")

解决方法

根据 api 的代码 https://github.com/tweepy/tweepy/blob/5b2dd086c2c5a08c3bf7be54400adfd823d19ea1/tweepy/api.py#L1144 api.search_full_archive 将标签(环境名称)和查询作为参数。如此变化

api.search_full_archive,environment_name='FullArchive',q=qt,fromDate=startdate,toDate=enddate,count=300,tweet_mode='extended'

api.search_full_archive,label='FullArchive',query=qt,toDate=enddate

至于 tweet_mode='extended',它不适用于 search_full_archive 和 search_30_day。您可以在 https://github.com/tweepy/tweepy/issues/1461

中查看如何访问全文