Python – Tweepy 中的 API.create_saved_search()
Twitter是一个流行的社交网络,用户在其中分享称为推文的消息。 Twitter 允许我们使用 Twitter API 或Tweepy挖掘任何用户的数据。数据将是从用户那里提取的推文。首先要做的是从 twitter 开发人员那里轻松获得每个用户可用的消费者密钥、消费者密钥、访问密钥和访问密钥。这些密钥将帮助 API 进行身份验证。
API.create_saved_search()
Tweepy 模块中API
类的create_saved_search()
方法用于为经过身份验证的用户创建保存的搜索。
Syntax : API.create_saved_search(query)
Parameter :
- query : the query of the search.
Returns : an object of class SavedSearch
示例 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 create_saved_search() : ", end = "")
print(len(api.saved_searches()))
# query of the new saved search
query = "Tweepy"
# creating the saved search
api.create_saved_search(query)
print("The number of saved searches after create_saved_search() : ", end = "")
print(len(api.saved_searches()))
输出 :
The number of saved searches before create_saved_search() : 3
The number of saved searches after create_saved_search() : 4
示例 2:获取新创建的已保存搜索。
# query of the new saved search
query = "News"
# creating the saved search
saved_search = api.create_saved_search(query)
# printing the information
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)
输出 :
The saved search 1269510986496569349 was created on : 2020-06-07 06:06:20
The query of the saved search is : News
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。