Pulling Twitter user profiles
For this recipe, we are going to use the Twitter API to pull JSON data about Twitter users. Each Twitter user, identified by either a screen name (such as SayHiToSean
) or a unique integer, has a profile containing a rich set of information about someone.
Getting ready
You will need the list of followers' and friends' IDs from the previous recipe, Determining your Twitter followers and friends.
How to do it...
The following steps guide you through retrieving a set of Twitter users' profiles:
- First, we create a function that will manage pulling Twitter profiles:
In [18]: def pull_users_profiles(ids):
...: users = []
...: for i in range(0, len(ids), 100):
...: batch = ids[i:i + 100]
...: users += twitter.lookup_user(user_id=batch)
...: print(twitter.get_lastfunction_header('x-rate-limit-remaining'))
...: return (users)
- We put this function to use, pulling profiles of both friends and followers:
In [19]: friends_profiles = pull_users_profiles...