Python – API.destroy_saved_search() 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.destroy_saved_search()
The destroy_saved_search()
method of the API
class in Tweepy module is used to delete a saved search for the authenticated user.
Syntax : API.destroy_saved_search(id)
Parameter :
- id : the ID of the saved search to be destroyed.
Returns : an object of class SavedSearch
Example 1 : Deleting a saved search.
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)
print ( "The number of saved searches before destroy_saved_search() : " , end = "")
print ( len (api.saved_searches()))
id = 1269510986496569349
api.destroy_saved_search( id )
print ( "The number of saved searches after destroy_saved_search() : " , end = "")
print ( len (api.saved_searches()))
|
Output :
The number of saved searches before destroy_saved_search() : 5
The number of saved searches after destroy_saved_search() : 4
Example 2 : Deleting all the saved searches.
saved_searches = api.saved_searches()
print ( "The number of saved searches before destroy_saved_search() : " , end = "")
print ( len (saved_searches))
for saved_search in saved_searches:
api.destroy_saved_search(saved_search. id )
print ( "The number of saved searches after destroy_saved_search() : " , end = "")
print ( len (api.saved_searches()))
|
Output :
The number of saved searches before destroy_saved_search() : 4
The number of saved searches after destroy_saved_search() : 0
Share your thoughts in the comments
Please Login to comment...