Search code examples
pythontwittertwitter-oauthtweepy

How to get hastahg, username tweets using tweepy


I written script for tweepy, where when I enter keyword like bse, nse it searches these keywords.

But when I enter hashtag #bse, #nse or user name @skirani , @mukund it gives no result.

I tried with both result_type, recent as well popular, no change. Is there any other result type?

def getTweets(self, data):
    import pdb
    # pdb.set_trace()
    tweets = {}
    if "query" in data:
        tweets = self.twitter_api.search(data['query'], result_type='recent' )
        # print type(tweets)
        result = tweets['statuses']
        count = 1
        for val in result:
            print count
            print val['text']
            count += 1
            print 
    return tweets     

Solution

  • Tweepy requires that search entities are URL encoded. That means that @ needs to be %40 and # must be %23

    A simple way to do this in Python is:

    import urllib2
    search = urllib2.quote("@skirani")