How to use the tweepy's search API?


When I’m crawling the tweets, I used the Tweepy.
I tried to search some tweets when they were written past periods (e.g. 2014.7.1 to 2014.7.31)
My python code is below.

    from tweepy import Stream
    from tweepy import OAuthHandler
    from tweepy.streaming import StreamListener
    import tweepy
    import time

    ckey ='x'
    csecret = 'x'
    atoken = 'x'
    asecret ='x'

    auth = tweepy.OAuthHandler(ckey, csecret)
    auth.set_access_token(atoken, asecret)

    api = tweepy.API(auth)

    for tweet in tweepy.Cursor(,q='test',since='2014-07-01',until='2014-07-31').items():
        print tweet.text

However, after compiling, I got this errors

    Traceback (most recent call last):
      File "D:\workplace\twitter_crawler\src\", line 98, in <module>
        for tweet in tweepy.Cursor(,q='name', since='2014-07-01',until='2014-07-31').items():
      File "build\bdist.win32\egg\tweepy\", line 181, in next
      File "build\bdist.win32\egg\tweepy\", line 101, in next
    AttributeError: 'function' object has no attribute '__self__'

How can I fix the AttributeErrors, could you help me my problems? Thanks for reading.


[I moved this post from the Streaming category to REST, since you’re not actually using the Streaming API]

Your code works fine for me (although I changed the dates to August (08) from July, as the Search index doesn’t go back further than 7-10 days).

What version of Python are you using? Tweepy doesn’t currently work fully on Python 3. There’s a forum for Tweepy run by the developers at which may be helpful for you.


Is there any method to collect tweets that are older than that time window? I’d like to collect tweets from the beginning of June 2014, that’s why I was wondering.


There’s no public search API that can help with that, I’m afraid - actually the search API has always been limited to a shorter period of time.

I realise that this may not be the answer you’re looking for, but we do offer the commercial Gnip API which enables search over the whole of the Twitter archive and with much greater granularity.



Is there a way to add a particular time to the search too?

for tweet in tweepy.Cursor(,q='test',since='2015-06-26 10:01:25',until='2015-06-26 10:15:10').items():

Would really like the help :slight_smile:


You can do hourly search by using since_id and max_id. since_id represents starting and max_id represents ending. See this tutorial