简体   繁体   English

较旧的推文 Tweepy 使用 Python

[英]Older tweets Tweepy using Python

I am trying to get older tweet data (approximately 2 months old) using tweepy in Python.我正在尝试使用 Python 中的 tweepy 获取较旧的推文数据(大约 2 个月大)。 I tried since and until parameters but no success.我试过自和直到参数但没有成功。 Has anyone got a work around in tweepy or some other API.有没有人在 tweepy 或其他一些 API 中得到解决。

for id,tweet in enumerate (tweepy.Cursor(api.search, q='SpecificWord', since="2016-04-26", until="2016-04-28", lang="en", include_retweets=False    ).items(200)):
     #Write a row to the csv file
     CSVW.writerow([tweet.created_at,    tweet.retweet_count,    tweet.text.encode('utf-8')])

This is not possible.这是不可能的。 The docs on the Twitter API are very clear : Twitter API 上的文档非常清楚

The Twitter Search API searches against a sampling of recent Tweets published in the past 7 days. Twitter Search API 根据过去 7 天内发布的近期推文样本进行搜索。

There is no way to search back further than that.没有办法比这更进一步搜索。

There are 2 ways to get older tweets.有两种方法可以获取较旧的推文。

  1. You get the forked version of Tweepy, which supports multiple authentication handlers.您将获得 Tweepy 的分叉版本,它支持多个身份验证处理程序。 Here is an instruction on how to use it (unfortunately only with Python 2.7).这是有关如何使用它的说明(不幸的是,仅适用于 Python 2.7)。 Or you use this ratetime limiter for Tweepy.或者您将这个速率时间限制器用于 Tweepy。 But with the Twitter API the oldest data you can get is about 7 days I think.但是使用 Twitter API,我认为您可以获得的最旧数据大约是 7 天。

  2. The other way is to use GetOldTweets-python , it also works with Python 3. Here is an example on how to use it.另一种方法是使用GetOldTweets-python ,它也适用于 Python 3。这是有关如何使用它的示例。

First Install lxml (Version 3.5) & pyquery Version 1.2.10):首先安装 lxml(3.5 版)和 pyquery 1.2.10 版):

pip3 install lxml==3.5.0
pip3 install pyquery==1.2.10

Then download GetOldTweets-python and copy the folder got3 into you site packages folder and run Python.然后下载 GetOldTweets-python 并将文件夹 got3 复制到您的站点包文件夹中并运行 Python。

import got3

max_tweets = 3

tweetCriteria = got3.manager.TweetCriteria().setUntil("2016-01-31").setQuerySearch("bitcoin").setMaxTweets(max_tweets)

for i in range(max_tweets):
    tweet = got3.manager.TweetManager.getTweets(tweetCriteria)[i]
    print(tweet.id)
    print(tweet.username)
    print(tweet.text)
    print(tweet.date)

Now you are getting Tweets from 2016!现在您将收到 2016 年的推文!

693584301917655041
bitcoinfirehose
Teenagers are using untraceable currency Bitcoin to buy dangerous drugs online http://ift.tt/20eIDwU #reddit #bitcoin
2016-01-31 00:59:18

693584300265070593
bitcoinfirehose
Hey guys I've seen a need to cashout to Visa. So I created a site to get moneypak codes via Bitcoin ! Please come check it out! …
2016-01-31 00:59:18

693584286210002944
b1eedr
Bitcoin 2.0: Fantasy Or Inevitability? https://www.cryptocoinsnews.com/bitcoin-2-0-fantasy-or-inevitability/ @CryptoCoinsNews
2016-01-31 00:59:14

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM