Python – API.search_users() in Tweepy
Last Updated :
05 Jun, 2020
Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from twitter developer available easily for each user. These keys will help the API for authentication.
API.search_users()
The search_users()
method of the API
class in Tweepy module is used to run a search based on a query and get users matching that query, similar to the Find People button.
Syntax : API.search_users(q, count)
Parameters :
q : the text to be searched
count : specifies the number of users to retrieve, cannot be greater than 20, the default value is 20
Returns : a list of objects of the class User
Example 1 :By default search_users()
retrieves 20 users.
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)
q = "geeks"
users = api.search_users(q)
for user in users:
print (user.screen_name)
|
Output :
GeeksOUT
GWOBorg
GeeksOfColor
geeksaresexy
WeatherGeeks
CoachingGeeks
DealsForGeeks
TwinCitiesGeeks
RetroGameGeeks
BuddhistGeeks
KevinGeeksOut
mcrgirlgeeks
AirplaneGeeks
AirlineGeeks
geeks_3d
GeeksGamersCom
javacodegeeks
wearemoviegeeks
The_GWW
GeeksRoom
Example 2: Using the count parameter to retrieve less than 20 users.
q = "geeksforgeeks"
count = 3
users = api.search_users(q, count)
for user in users:
print (user.screen_name)
|
Output :
geeksforgeeks
gfgvideos
gfg_reader
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...