Search code examples
pythontwittertweepy

Tweepy Look up ID with username


I am trying to get a list of IDs from a list of usernames I have. Is there any method that tweepy provides that lets me do lookup user IDs using their username?


Solution

  • Twitter API has the resource https://dev.twitter.com/rest/reference/get/users/lookup for such requirements. It can return user objects for at most 100 users at a time.

    You can use this in Tweepy like:

    user_objects = api.lookup_users(screen_names=list_of_at_most_100_screen_names)
    user_ids = [user.id_str for user in user_objects]