I am trying to extract followers and following counts of different Twitter users with the help of Tweepy but I keep getting error, [{'code': 89, 'message': 'Invalid or expired token.'}]
.
All I need is the count (not the list of followers/friends) because some have millions of followers. I could have gone manually to check for each Twitter handle but that is impracticable since I have close to 20000 users I am trying to check out.
Thank you
import tweepy
from requests_oauthlib import OAuth1
# Keys, tokens and secrets
consumer_key = " my api_key"
consumer_secret = "my api_secret_key"
key = "my access_token"
secret = " my access_token_secret"
# Tweepy OAuthHandler
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(key,secret)
api = tweepy.API(auth)
targets = ['FoxNews', 'XHNews', 'Reuters', 'AP', 'MTV', 'CNN']
for target in targets:
user = api.get_user(target)
print(user.name, user.followers_count)
OUTPUT: TweepError: [{'code': 89, 'message': 'Invalid or expired token.'}]