'How to get public metrics for >3K list of twitter ids using API V2 in Pyspark

I have a dataset of more than 3K twitter ids for which I need to retrieve the public metrics (retweet_count, reply_count, like_count) and author_id and after this save all the info in a dataframe. I've tried to use get_tweet from API v2 but it looks like it only accepts one twitter id at a time:

twitter_client = tweepy.Client(TW_bearer_token, TW_api_key, TW_api_key_secret)

tweets = twitter_client.get_tweet(1019696670777503745, tweet_fields=['public_metrics']).data.public_metrics

Any idea on how I could retrieve these info and then append it to a dataframe?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source