geduldig / TwitterAPI

Minimal python wrapper for Twitter's REST and Streaming APIs
938 stars 263 forks source link

Using api.request with search tweets but exclude retweets #150

Closed wlwatkins closed 3 years ago

wlwatkins commented 3 years ago

I am posting a new issue as to get an opened ticket. This is a follow up to #149

I'm following up this question, I had already found the standard operators page, but I don't understand how to combine this with a search

r = api.request({'search/tweets': {'q':'puppy', 'count': 20}, "statuses/filter": "retweets"})

does not work

dbrennand commented 3 years ago

Hi @willmendil

search/tweets and statuses/filter are two separate API endpoints. What you’re looking for is to combine either one of those endpoints with the second parameter for the request method which is params. This parameter takes a dictionary so you were on the right lines there 👍🏻

I will give a nice example. Say I want to use the search endpoint to get all of Donald Trumps latest 10 tweets which are not retweets. I would do the following:

# Assuming you have already authenticated above
api = api.request(“search/tweets”, {“q”: “from:realdonaldtrump -filter:retweets”, “count”: “10”, “result_type”: “recent”})

# Interact with Tweets here

Hope this helps! 👍🏻

wlwatkins commented 3 years ago

Ok, got it, works great, thanks !