Adding search operators to TwitterAPI (Premium Search)

python

#1

I am using the TwitterAPI library in Python with the 30 day Premium API (Sandbox mode). Everything works until I try to add more search operators such as ‘maxResults’ : ‘500’. Whenever I add a new operator I get a 422 error. What is the right way to use these operators in a query? I have tried adapting the example given in the Twitter Documentation for ‘Example POST Request’ (https://developer.twitter.com/en/docs/tweets/search/api-reference/premium-search#DataEndpoint), but nothing seems to work.

My code is as follows:

from TwitterAPI import TwitterAPI

SEARCH_TERM = ‘#Dáil100 OR #soloheadbeg lang:en’
PRODUCT = ‘30day’
LABEL = ‘dev’

api = TwitterAPI("XXXX",
                 "XXXX",
                 "XXXX",
                 "XXXX",
                 auth_type='oAuth2')

r = api.request('tweets/search/%s/:%s' % (PRODUCT, LABEL),
                   {'query': SEARCH_TERM, "maxResults":"500"})

for item in r:
    print(item[‘text’] if ‘text’ in item else item)

#2

That looks ok, except maxResults is limited to 100 in Sandbox mode https://developer.twitter.com/en/account/subscriptions/search-30day


#3

(Also, in case you’re not doing it already: To save on calls, It’s worth using the Standard API Search to get the last 7 days of tweets, and Fullarchive search for >30 days ago for the Dail100 Tweets in January)


#4

Thank you this worked - figured it must be something really simple that I was just not seeing anymore! And yes been using standard API up til now but using the 30day sandbox to test out for using fullarchive eventually.