I wrote a code to send follow request to specific users and my logic also seems perfect. Even when I print response.data it shows me my followers' data in a dictionary. But I can't find a way to fetch those names altogether and compare with the specific name of the person I want to follow.
import tweepy
import api_keys as ak
def about_me(client: tweepy.Client) -> None:
"""Print information about the client's user."""
# The `public_metrics` addition will give me my followers count, among other things
me = client.get_me(user_fields=["public_metrics"])
print(f"My name: {me.data.name}")
print(f"My handle: @{me.data.username}")
print(f"My followers count: {me.data.public_metrics['followers_count']}")
print(f"My User ID: {me.data.id}")
if __name__ == "__main__":
client = tweepy.Client(
bearer_token=ak.Bearer_Key,
consumer_key=ak.API_Key,
consumer_secret=ak.API_Key_Secret,
access_token=ak.Access_Token,
access_token_secret=ak.Access_Token_Secret)
print("=== About Me ===")
about_me(client)
for response in tweepy.Paginator(client.get_users_followers, 2351371758, max_results=10, limit=5):
df = pd.DataFrame(response.data)
print(df)
if df['name'] == 'Leta Disandro':
response.follow_user()
It even stores my requested data into a dataframe but throws error when I try to check for the name in that dataframe. I even tried different variations and these are the errors I encountered:
raise ValueError(ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
AttributeError: 'Response' object has no attribute 'follow'
AttributeError: 'Response' object has no attribute 'follow_user'