I am currently trying to write a bot which only collects tweets from specific accounts. For that I use Tweepy V2 api to filter the stream with a streaming_client in Python as follows:
class TweetPrinterV2(tweepy.StreamingClient):
def on_tweet(self, tweet):
print(tweet.text)
return
streaming_client=TweetPrinterV2('bearertoken')
streaming_client.add_rules(tweepy.StreamRule("from:samsung"))
streaming_client.filter(tweet_fields=['author_id'])
However when I do that I always get this error:
Traceback (most recent call last):
File "/home/julian/Documents/bot/bot.py", line 48, in <module>
streaming_client.add_rules(tweepy.StreamRule("from:samsung"))
File "/home/julian/.local/lib/python3.10/site-packages/tweepy/streaming.py", line 681, in add_rules
return self._make_request(
File "/home/julian/.local/lib/python3.10/site-packages/tweepy/client.py", line 129, in _make_request
response = self.request(method, route, params=request_params,
File "/home/julian/.local/lib/python3.10/site-packages/tweepy/client.py", line 119, in request
raise HTTPException(response)
tweepy.errors.HTTPException: 422 Unprocessable Entity
So it does not work and I get a 422 error. When I use the negated version '-from:samsung', it works perfectly fine. Searching by keywords also works.
But the positive filter by a certain author does not work. Normally it should work such that the stream only shows tweets by the author 'samsung'. It does not work as shown above. How can I filter my stream so it only outputs tweets from certain authors?