Python – API.saved_searches() in Tweepy
Last Updated :
10 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.saved_searches()
The saved_searches()
method of the API
class in Tweepy module is used to get the saved searches of the authenticated user.
Syntax : API.saved_searches()
Parameters : None
Returns : a list of objects of class SavedSearch
Example 1 : Printing the query and the ID of the saved searches.
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)
saved_searches = api.saved_searches()
for saved_search in saved_searches:
print ( "The ID of this saved search is : " + str (saved_search. id ))
print ( "The query of this saved search is : " + saved_search.query, end = "\n\n" )
|
Output :
The ID of this saved search is : 1269502915346980864
The query of this saved search is : geeks
The ID of this saved search is : 1269502963724115972
The query of this saved search is : geeksforgeeks
The ID of this saved search is : 1269503225993900032
The query of this saved search is : computer
Example 2 : Count the number of saved searches.
saved_searches = api.saved_searches()
print ( len (saved_searches))
|
Output :
3
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...