I'm super new to Python but I am trying to access the Twitter API to pull in the number of followers for a list of twitter handles (or user IDs - i have both datasets) and print them to a csv file. I've searched for quite some time for this but haven't found anything that has truly worked.
This is what I currently have:
import tweepy
import time
import csv
import sys
# Keys, tokens and secrets
consumer_key = 'REMOVED'
consumer_secret = 'REMOVED'
access_token = 'REMOVED'
access_token_secret = 'REMOVED'
# Tweepy OAuthHandler
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
targets = [12345,123456] # All your targets here
for target in targets:
user = api.get_user(target)
print(user.name, user.followers_count)
My questions here are:
Can I have all the targets in a pre populated file and have the follower count for each target print out in the column next to the IDs?
How do I add in count-break since: The twitter API only allows 100 users to be searched for at a time...[so] what you'll need to do is iterate through each 100 users but staying within the rate limit.
Apologies if this is super basic and thanks in advance for any help!