Search code examples
iosswifttwittertwitter-oauth

How to find several users using users/lookup twitter api?


My goal is to retrieve relevant users based on the search field using twitter api https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-users-lookup. I am sending screen name to twitter api inorder to get the results.

For some reason, twitter search with an exact match. For instance, see below word "Elo" where my intention was search all the users that begins with Elo.

I am unsure right now if Twitter doesn't perform search like that or is there any additional parameters needed to pass such filters.

Any help is appreciated.

enter image description here


Solution

  • You are using the wrong API for your use case. This API is for converting exact user names into user objects (to fetch id's, profile pictures etc). The requirement is to pass exact usernames, separated by commas, and it will return an object for each.

    What you are looking for is search, not lookup:

    https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-users-search