I am trying to match Tweet data with User information using the Paginator, but am encountering problems with missing User information.
This is my code for matching the tweet strings with user metadata:
client = tweepy.Client(bearer_token=config.BEARER_TOKEN, consumer_key=
config.CONSUMER_KEY,consumer_secret= config.CONSUMER_SECRET,access_token=
config.ACCESS_TOKEN,access_token_secret= config.ACCESS_TOKEN_SECRET)
for tweet_batch in tweepy.Paginator(client.search_all_tweets, query=s,
tweet_fields=['context_annotations','created_at', 'public_metrics','author_id', 'lang', 'geo', 'entities'],
user_fields=['name','username','location','verified','description'],
max_results=100, expansions='author_id'):
tweet_data = tweet_batch.data
users = tweet_batch.includes['users']
print(len(tweet_data),len(users))
The output of the lists were of different lengths:
40 38
tweet_batch consists of the Response form (Personal data removed):
Response(data=[<Tweet id = 123, text = "abc">, <Tweet id = 456, text = "def">], includes={'users':[<User id = 9765, name="foo">]})
The problem is that due to the seperation of 'users' from 'data', there is no method to match corresponding Tweet text to User id if the lengths are mismatched.
Are there any better workarounds?