簡體   English   中英

較舊的推文 Tweepy 使用 Python

[英]Older tweets Tweepy using Python

我正在嘗試使用 Python 中的 tweepy 獲取較舊的推文數據(大約 2 個月大)。 我試過自和直到參數但沒有成功。 有沒有人在 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')])

這是不可能的。 Twitter API 上的文檔非常清楚

Twitter Search API 根據過去 7 天內發布的近期推文樣本進行搜索。

沒有辦法比這更進一步搜索。

有兩種方法可以獲取較舊的推文。

  1. 您將獲得 Tweepy 的分叉版本,它支持多個身份驗證處理程序。 這是有關如何使用它的說明(不幸的是,僅適用於 Python 2.7)。 或者您將這個速率時間限制器用於 Tweepy。 但是使用 Twitter API,我認為您可以獲得的最舊數據大約是 7 天。

  2. 另一種方法是使用GetOldTweets-python ,它也適用於 Python 3。這是有關如何使用它的示例。

首先安裝 lxml(3.5 版)和 pyquery 1.2.10 版):

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

然后下載 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)

現在您將收到 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