Tweepy is a python library for accessing twitter's API. My aim was to get the list of people that I am following, but I found out that this was not straight-forward. You can easily get a list of your friends tweepy.API().friends()
, though the size of the list is limited due to pagination. The more convenient workaround to get the full list of people was to get the unique IDs as integers and then ask for their screen_name
.
This example demonstrates the limited size of the list due to pagination.
import tweepy consumer_key = "" consumer_secret = "" access_token = "" access_token_secret = "" auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) user = api.get_user('aucotsi') l = list() for friend in user.friends(): l.append(friend.screen_name) print('Total friends: ', len(l))
Total friends: 20
This example demonstrates a workaround to overcome pagination.
user = api.get_user('aucotsi') l = list() for friend in api.friends_ids(): u = api.get_user(friend) l.append(u.screen_name) print('Total friends: ', len(l))
Total friends: 474
In the API reference you can find timeline, status, user and search methods among others.