Sunday, November 17, 2024
Google search engine
HomeLanguagesPython – API.saved_searches() in Tweepy

Python – API.saved_searches() in Tweepy

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 the module
import tweepy
  
# assign the values accordingly
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
  
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  
# set access to user's access key and access secret 
auth.set_access_token(access_token, access_token_secret)
  
# calling the api 
api = tweepy.API(auth)
  
# fetching the saved searches
saved_searches = api.saved_searches()
  
# printing the information
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 : neveropen

The ID of this saved search is : 1269502963724115972
The query of this saved search is : neveropen

The ID of this saved search is : 1269503225993900032
The query of this saved search is : computer

Example 2 : Count the number of saved searches.




# fetching the saved searches
saved_searches = api.saved_searches()
  
# printing the number of saved searches
print(len(saved_searches))


Output :

3

Last Updated :
10 Jun, 2020
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments