如何从推特 API 中提取历史推文? [英] How to extract the historical tweets from twitter API?

查看:1332
本文介绍了如何从推特 API 中提取历史推文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要一些电影的历史推文.现在,我们尝试了 twitter 的流 API 和搜索 API.流 API 不能给我们一个参数来选择我们需要的时间范围,搜索 API 只能提前一两周给我们数据.有没有办法提取2014-05-01到2014-07-01的历史推文(例如)?我发现以下方法可以做到这一点:

We need the historical tweets for some movies. Right now, we tried the streaming API and search API from twitter. The streaming API could not give us a parameter to choose the time range we need and the search API could only give us data one or two weeks in advance. Is there a way for us to extract the historical tweets from 2014-05-01 to 2014-07-01 (For example)? I found the following ways that is possible to do that:

1:推特高级搜索https://twitter.com/search-advanced?lang=en它可以找到我需要的搜索结果.但是我怎么能下载搜索结果呢?有没有办法写个代码保存搜索结果?

1: Twitter advanced search https://twitter.com/search-advanced?lang=en It could find the search result I need. But how could I download the search result? Is there anyway to write a code and save the search result?

2:像topsy一样使用推特分析网站.但它也有保存结果的困难.

2:Using the twitter analytic website like topsy. But it also has the difficulty to save the result.

3:似乎像 twitter4J 这样的一些软件包可以帮助解决这个问题:http://twitter4j.org/en/code-examples.html是否有任何 python 或 R 包可以帮助我们做到这一点?

3: It seems that some packages like twitter4J could help with that: http://twitter4j.org/en/code-examples.html Is there any python or R package could help us to do that?

4:我们需要这些数据来进行研究.花费很长时间来提取数据并不是一个好的选择.有没有什么专业的网站可以买到这些数据?

4: We need this data to do a research. It is not a good choice to spend a long time for the extraction of the data. Is there anyway to buy this data from some professional website?

推荐答案

您可以使用以下库 https://github.com/Jefferson-Henrique/GetOldTweets-python 在 Twitter 中获取旧推文.

You can use the following library https://github.com/Jefferson-Henrique/GetOldTweets-python to get old tweets in Twitter.

使用

 cd GetOldTweets-python

然后执行以下操作

在 Python 中,

In Python,

import got
tweetCriteria = got.manager.TweetCriteria().setQuerySearch('search_term').setSince("2014-05-01").setUntil("2014-07-01").setMaxTweets(10000)
tweet = got.manager.TweetManager.getTweets(tweetCriteria)[0]

print tweet.text

在终端中,

python Exporter.py --querysearch 'search_term' --since 2014-05-01 --until 2014-07-01 --maxtweets 10000

用搜索词替换search_term".

Replace 'search_term' with the search term.

这篇关于如何从推特 API 中提取历史推文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆