I’m trying to query recent tweets by the author_id parameter.
Code I’m trying:
def make_request(headers):
url = "https://api.twitter.com/2/tweets/search/recent"
params = {'query':'author_id:17469289',
'expansions': 'in_reply_to_user_id,referenced_tweets.id,entities.mentions.username,referenced_tweets.id.author_id,author_id',
'tweet.fields': 'id,text,author_id,conversation_id,created_at,geo,lang,referenced_tweets,public_metrics',
'user.fields': 'id,name,username,created_at,description,location,public_metrics',
'place.fields': 'full_name,id,country,country_code,geo,name,place_type'}
return requests.request("GET", url, params=params, headers=headers).json()
response = make_request(headers)
print(response)
However, that’s returning the following error message:
{'errors': [{'parameters': {'query': ['author_id:17469289']}, 'message': "There were errors processing your request: Reference to invalid field 'author_id' (at position 1), Reference to invalid operator 'author_id'. Operator is not available in current product or product packaging. Please refer to complete available operator list at http://t.co/operators. (at position 1)"}], 'title': 'Invalid Request', 'detail': 'One or more parameters to your request was invalid.', 'type': 'https://api.twitter.com/2/problems/invalid-request'}
However, if I change the search query to conversation_id and a value, it works fine.
params = {'query':'conversation_id:1526963484109438976', …
The documentation link referenced in the error message (http://t.co/operators) doesn’t give me any indication parameter relationship difference between the author_id query vs conversation_id. Both are in the tweet.fields expansions, so I don’t get why one returns a result but not the other.
Greatly appreciate any input into what I’m doing wrong.