Search code examples
pythontweepytwitterapi-python

Unable to retrieve public metrics using tweepy.Client


I don't know what the deal is, but I'm trying to get user info by usernames and include their public_metrics from the Twitter API using tweepy.

Here's my code:

import tweepy
BEARER_TOKEN = 'a 100% real API secret publicly posted on SO'
tweepyClient = tweepy.Client(BEARER_TOKEN)
response = tweepyClient.get_users(usernames=['ThreatLevelGG', 'Twitter', 'TwitterDev'], user_fields=['public_metrics'])

However, it's only returning the default info: enter image description here

Am I stupidly missing something simple, or does tweepy suck?


Solution

  • From the relevant FAQ section in Tweepy's documentation about this:

    If you are simply printing the objects and looking at that output, the string representations of API v2 models/objects only include the default attributes that are guaranteed to exist.

    The objects themselves still include the relevant data, which you can access as attributes or by key, like a dictionary.