📜  Python – Tweepy 中的 API.destroy_saved_search()

📅  最后修改于: 2022-05-13 01:55:03.320000             🧑  作者: Mango

Python – Tweepy 中的 API.destroy_saved_search()

Twitter是一个流行的社交网络,用户在其中分享称为推文的消息。 Twitter 允许我们使用 Twitter API 或Tweepy挖掘任何用户的数据。数据将是从用户那里提取的推文。首先要做的是从 twitter 开发人员那里轻松获得每个用户可用的消费者密钥、消费者密钥、访问密钥和访问密钥。这些密钥将帮助 API 进行身份验证。

API.destroy_saved_search()

Tweepy 模块中API类的destroy_saved_search()方法用于删除已保存的已验证用户搜索。

示例 1:删除已保存的搜索。

# 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)
  
print("The number of saved searches before destroy_saved_search() : ", end = "")
print(len(api.saved_searches()))
  
# query of the saved search
id = 1269510986496569349
  
# deleting the saved search
api.destroy_saved_search(id)
  
print("The number of saved searches after destroy_saved_search() : ", end = "")
print(len(api.saved_searches()))

输出 :

The number of saved searches before destroy_saved_search() : 5
The number of saved searches after destroy_saved_search() : 4

示例 2:删除所有已保存的搜索。

# fetching all the saved searhces
saved_searches = api.saved_searches()
  
print("The number of saved searches before destroy_saved_search() : ", end = "")
print(len(saved_searches))
  
# deleting all the saved search
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()))

输出 :

The number of saved searches before destroy_saved_search() : 4
The number of saved searches after destroy_saved_search() : 0