pythonpython-2.7apitwitterpython-twitter

How to search for gifs in Twitter API?


I'm using python-twitter to build an application that would search for all the tweets including gifs in a given time range for a set of users.

For example, I'd like to get all the gifs from user @NHLJets during the interval 2017-03-21 -> 2017-03-22.

I know how to get all the rest

import twitter api = twitter.Api(...) # The API keys inside the call print api.GetSearch(raw_query='from=NHLJets&since=2017-03-21&until=2017-03-22')

Using the Twitter Advanced Search, I can just say q=gif and it works but for some reason using the python-twitter's api.GetSearch it returns an empty list.

In[34]: api.GetSearch(raw_query='q=gif&from=NHLJets') Out[34]: []

I'm willing to change from python2.7 to python3, I'm willing to change Twitter libraries - just curious to know if someone has figured this one out yet?


Solution

  • the Twitter operator you're looking for is card_name:animated_gif. The only problem with this operator is that it gives results only 7 days back, so for your query:

    from:NHLJets since:2017-03-21 until:2017-03-22 card_name:animated_gif
    

    you'll get nothing (try...). Even if you remove the dates you'll probably get nothing unless they actually posted a gif in the last 7 days.

    One way to get around it is to archive gif tweets in real (or close to real) time from a twitter list containing all the accounts of interest. Here is an example of all the tweets containing animated gifs by all of Twitter's official accounts:

    card_name:animated_gif list:84839422
    

    Try it...