Searching of public tweets with hashtag in certain period of time

孤街浪徒 提交于 2019-12-08 09:05:10

问题


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])

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


回答1:


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.



来源:https://stackoverflow.com/questions/29595714/searching-of-public-tweets-with-hashtag-in-certain-period-of-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!