Reputation: 7577
So here is my simple code:
import tweepy
import pandas as pd
def getClient():
client = tweepy.Client(bearer_token='XXXX')
return client
def getUserInfo(username):
client.get_user(username=username,user_fields='public_metrics')
return user
usr =getUserInfo('elonmusk')
Question is how does one now access the follower count from public_metrics? I have read that its stored as a dict and simply trying to read is using usr.data.public_metrics won't return it, but I haven't seen anyone demonstrate the correct way to access the public_metrics data?
Upvotes: 0
Views: 1122
Reputation: 7577
Ok I spotted an error in my code. Posting the answer here so it helps others.
import tweepy
import pandas as pd
def getClient():
client = tweepy.Client(bearer_token='XXXX')
return client
def getUserInfo(client,username):
user = client.get_user(username=username,user_fields='public_metrics')
return user
client = getClient()
d =getUserInfo(client,'ElonMusk')
d.data.public_metrics['followers_count']
Upvotes: 1