Reputation: 187
I have a list of people names and want to find out if they have Twitter accounts, unreliable as that may be. How can I do it on Tweepy?
I am trying to pass user.name as an argument for the query, but it just seems to allow for searching their screen_names or ids.
user = api.get_user(screen_name='georgetakei')
print(user.name)
**> George Takei**
But if I try the other way round...
user = api.get_user(name='George Takei')
print(user.screen_name)
**> TweepError: [{'code': 50, 'message': 'User not found.'}]**
Is there a workaround?
Upvotes: 0
Views: 210
Reputation: 834
Could you use the api.search_users()
method?
Example using a list
#Search for users by name
name = 'George Takei'
users = api.search_users(q=name)
#Print the screen_name of the first matching user
if len(users) > 0:
print(users[0].screen_name)
else:
print("No user found with that name.")
Not 100% sure, but I think api.search_users(q, count)
should work as well. As in q
being query and count
being the number of users to be retrieved
Upvotes: 2