tweepy.Cursor 中的属性是在特定时间之前打印推文?

What is the attribute in tweepy.Cursor to print tweets before a certain time?

我已指定提取自指定日期以来的推文,但我还需要提取指定日期之前的推文。 since 关键字用于提取自给定日期以来的推文。所以必须有一个关键字来提取指定日期之前的推文。该关键字是什么以及如何使用它?

    import tweepy

    import csv

    import pandas as pd

    ####input your credentials here

    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)

    csvFile = open('demon4.csv', 'a')

    csvWriter = csv.writer(csvFile)

    for tweet in tweepy.Cursor(api.search,q="#unitedAIRLINES",count=100,lang="en",\

                               since="2017-04-03").items():

        print (tweet.created_at, tweet.text)

        csvWriter.writerow([tweet.created_at, tweet.text.encode('utf-8')])

在 "q" 参数中,您可以像这样使用 "since" 和 "until" :

q="#unitedAIRLINES since:2017-04-02 until:2017-04-03"

结果应该和官网高级搜索一样:

https://twitter.com/search?f=tweets&vertical=default&q=%23unitedAIRLINES%20since%3A2017-04-02%20until%3A2017-04-03&src=typd

除了 public 搜索 API 你只能得到 7 天过去。

您可以使用特定的推文 ID 作为起点。参数为"since_id"。和一个 "max_id" 来分隔句点。有关详细信息,请参阅:https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html