I’m using python to make search queries. I’ve made successful calls using standard search. When I switch to Premium/ Sandbox/ 30-Day option, it will return an error message.
Instructions in developer(dot)twitter(dot)com seems to suggest the standard search uses “q”, whereas premium searches use “query”. And “query” seems to be the only mandatory parameter. I kept it simple whilst I test the proof of concept.
Standard search
TWITTER_URL = ‘https://api.twitter.com/1.1/search/tweets.json’
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
keyword = ‘dogs’
url = twurl.augment(TWITTER_URL,
{‘q’: keyword})
connection = urllib.request.urlopen(url, context=ctx)
data = connection.read().decode()
js = json.loads(data)
print(json.dumps(js, indent=2))
Premium/ 30-Day option
TWITTER_URL = ‘https://api.twitter.com/1.1/tweets/search/30day/prod.json’
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
keyword = ‘dogs’
url = twurl.augment(TWITTER_URL,
{‘query’: keyword})
connection = urllib.request.urlopen(url, context=ctx)
data = connection.read().decode()
js = json.loads(data)
print(json.dumps(js, indent=2))
Error message from the 30-Day option
connection = urllib.request.urlopen(url, context=ctx)
… …
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 422: Unprocessable Entity
Screenshot below: