Python – API.create_saved_search() 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.create_saved_search()
The create_saved_search()
method of the API
class in Tweepy module is used to create a saved search for the authenticated user.
Syntax : API.create_saved_search(query)
Parameter :
- query : the query of the search.
Returns : an object of class SavedSearch
Example 1 : Creating a saved search query.
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 create_saved_search() : " , end = "")
print ( len (api.saved_searches()))
query = "Tweepy"
api.create_saved_search(query)
print ( "The number of saved searches after create_saved_search() : " , end = "")
print ( len (api.saved_searches()))
|
Output :
The number of saved searches before create_saved_search() : 3
The number of saved searches after create_saved_search() : 4
Example 2 : Getting the newly created saved search.
query = "News"
saved_search = api.create_saved_search(query)
print ( "The saved search " + str (saved_search. id ) +
" was created on : " + str (saved_search.created_at))
print ( "The query of the saved search is : " + saved_search.query)
|
Output :
The saved search 1269510986496569349 was created on : 2020-06-07 06:06:20
The query of the saved search is : News
Last Updated :
10 Jun, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...