Help with 422 error

python

#1

This is my code. My keys are in another file called twitter_keys. I just want to be able to use the 30day/full endpoint provided in the premium package with Python.

from TwitterAPI import TwitterAPI
import twitter_keys

SEARCH_TERM = ‘#brexit -filter:retweets’
PRODUCT = ‘30day’
LABEL = ‘dev’

api = TwitterAPI(twitter_keys.CONSUMER_KEY, twitter_keys.CONSUMER_SECRET, twitter_keys.ACCESS_TOKEN, twitter_keys.ACCESS_TOKEN_SECRET)

r = api.request(‘tweets/search/%s/:%s’ % (PRODUCT, LABEL), {‘query’: SEARCH_TERM})

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

However I get this error:

TwitterAPI.TwitterError.TwitterRequestError: Twitter request failed (422)

It doesn’t allow me to include more options in my search, such as filtering out the retweets. Also, can someone provide some assistance and explain how the endpoint works and how its different to an API? I’ve only used the Standard API so far.


#4

Hi @YiannisHj - first off, -filter:retweets is not an operator supported by the premium version of the API. Instead, try replacing it with -is:retweet. Please refer to our documentation here to see a list of operators available by product.

In terms of the difference between the standard APIs and the premium APIs, the premium APIs include functionality beyond what is available with the standard APIs. For example:

  • more Tweets per request
  • higher rate limits
  • more complex queries
  • different operators (this is the reason your code above wasn’t working)
  • metadata enrichments
  • etc.

We provide detailed documentation for each available endpoint (both standard and premium), where you can find more information. A list of all available endpoints can be found here.

I hope this helps. Let us know if you have any more questions.


#5

Hi @Aurelia,
Thank you for replying. I tried changing the operator but I still get the same error.
I will try using https://github.com/twitterdev/search-tweets-python if TwitterAPI doesn’t work for me.


#6

@YiannisHj Are you using one of the paid Search APIs? The -is:retweet operator is only supported by those APIs.


#7

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.