在特定时间段内搜索带有主题标签的公共推文 [英] Searching of public tweets with hashtag in certain period of time

查看:24
本文介绍了在特定时间段内搜索带有主题标签的公共推文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently working on a project that related to Twitter data. I have read some information about the Twitter API and created a simple client app which aims to retrieve all public tweets containing specific keywords started from August 2013. However, my code does not give any output. I've tried using twitter4j and tweepy. Here is the code that I wrote in 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])

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

However, from here I knew that It is not possible to retrive tweets from two years ago. Despite this, is there any way how to get the old tweets from Twitter using any of twitter's API? Any feedback would be greatly appreciated. Thanks

推荐答案

很遗憾没有,使用公共 Twitter API 无法做到这一点.您只能在时间线中返回 3,200 条最近的推文,或搜索大约 7-10 天的数据.对于历史数据,您需要使用 Gnip 等商业服务.

Unfortunately no, there is no way to do this using the public Twitter API. You can only navigate back 3,200 of the most recent Tweets in a timeline, or search for about 7-10 days worth of data. For historic data, you need to use a commercial service such as Gnip.

这篇关于在特定时间段内搜索带有主题标签的公共推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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