📌  相关文章
📜  Python – Tweepy 中的 API.update_list()

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

Python – Tweepy 中的 API.update_list()

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

API.update_list()

Tweepy 模块中API类的update_list()方法用于更新列表。

示例 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)
  
# the screen name of the owner of the list
owner_screen_name = 
  
# the ID of the list
list_id = print("Before using update_list() method")
print("The name of the list is : " + api.get_list(list_id = list_id).name)
  
# the new name of the list
new_name = "Modified List"
  
# updating the list
api.update_list(list_id, name = new_name)
  
print("After using update_list() method")
print("The name of the list is : " + api.get_list(list_id = list_id).name)

输出 :

Before using update_list() method
The name of the list is : Sample List
After using update_list() method
The name of the list is : Modified List

示例 2:更新列表的描述。

# the screen name of the owner of the list
owner_screen_name =
  
# the ID of the list
list_id = print("Before using update_list() method")
print("The description of the list is : " + api.get_list(list_id = list_id).description)
  
# the new description of the list
new_description = "This list is to test the Twitter API."
  
# updating the list
api.update_list(list_id, description = new_description)
  
print("After using update_list() method")
print("The description of the list is : " + api.get_list(list_id = list_id).description)

输出 :

Before using update_list() method
The description of the list is : 
After using update_list() method
The description of the list is : This list is to test the Twitter API.