从推特检索推文

时间:2018-07-30 05:30:44

标签: python api twitter tweepy

我想从twitter检索推文并将其保存在CSV文件中。我使用以下代码,但未显示任何结果,也没有错误。怎么了?

import tweepy
import csv

consumer_key = 'xxx'
consumer_secret = 'xxx'
access_token = 'xxx'
access_token_secret = 'xxx'

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

search = raw_input('Search :> ')
csvFile = open('result.csv', 'a')
csvWriter = csv.writer(csvFile)
for tweet in tweepy.Cursor(api.search,
                            q='{}'.format(search),
                            since = "2018-07-1",
                            until = "2018-07-4",
                            lang = "ar").items():
    csvWriter.writerow([tweet.created_at, tweet.text.encode('utf-8')])
    print tweet.created_at, tweet.text
csvFile.close()

1 个答案:

答案 0 :(得分:1)

免费的API仅返回最近7 days(1周)内的推文。您正在搜索早于此的推文:/