【问题标题】:Searching of public tweets with hashtag in certain period of time在特定时间段内搜索带有标签的公共推文
【发布时间】:2015-06-18 04:42:29
【问题描述】:

我目前正在从事一个与 Twitter 数据相关的项目。我已经阅读了有关 Twitter API 的一些信息,并创建了一个简单的客户端应用程序,旨在检索从 2013 年 8 月开始包含特定关键字的所有公共推文。但是,我的代码没有给出任何输出。我试过使用 twitter4j 和 tweepy。这是我用 Python 写的代码

__author__ = 'adichris'
import tweepy
from tweepy import Stream
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
import json
import datetime

consumerKey = 'vSjDyEGe9.........'
consumerSecret = 'uXYFZUtO7cEG8x.......'
accessToken = '277834326-CWwhpL............Pp.........'
tokenSecret = 'izE......0Y.....5....W'

auth = tweepy.OAuthHandler(consumerKey, consumerSecret)
auth.set_access_token(accessToken, tokenSecret)

def date_range(start,end):
    current = start
    while (end - current).days >= 0:
        yield current
        current = current + datetime.timedelta(seconds=50)

class TweetListener(StreamListener):
    def on_status(self, status):
        startDate = datetime.datetime(2015,1,01)
        stopDate = datetime.datetime(2015,4,20)
        for date in date_range(startDate,stopDate):
            status.created_at = date
            print "tweet" + str(status.created_at)+"\n"
            print status.text + "\n"

stream = Stream(auth,TweetListener(),secure=True,)
t = u'#dearmentalhealthprofessional'
stream.filter(track=[t])

但是,从here 我知道不可能检索两年前的推文。尽管如此,有什么方法可以使用任何 Twitter 的 API 从 Twitter 获取旧推文? 任何反馈将不胜感激。谢谢

【问题讨论】:

    标签: api search twitter tweepy


    【解决方案1】:

    很遗憾,没有办法使用公共 Twitter API 来执行此操作。您只能在时间线中导航回 3,200 条最新推文,或搜索大约 7-10 天的数据。对于历史数据,您需要使用 Gnip 等商业服务。

    【讨论】:

    • 非常感谢您的反馈。我正在考虑使用 datasift 服务来做到这一点。
    猜你喜欢
    • 2014-01-02
    • 1970-01-01
    • 2011-07-13
    • 1970-01-01
    • 2011-08-27
    • 1970-01-01
    • 2012-11-09
    • 2012-08-29
    • 1970-01-01
    相关资源
    最近更新 更多