Python – API.update_list() 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.update_list()
The update_list()
method of the API
class in Tweepy module is used to update a list.
Syntax : API.update_list(parameters)
Parameters :
- list_id : ID of the list.
- slug : slug of the list, will have to also mention owner_id/owner_screen_name.
- name : name of the list.
- mode : mode of the list.
- description : description of the list.
- owner_id : ID of the owner of the list.
- owner_screen_name : screen name of the owner of the list.
Returns : an object of class List
Example 1 : Changing the name of the list.
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)
owner_screen_name =
list_id = print ( "Before using update_list() method" )
print ( "The name of the list is : " + api.get_list(list_id = list_id).name)
new_name = "Modified 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)
|
Output :
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
Example 2 : Updating the description of the list.
owner_screen_name =
list_id = print ( "Before using update_list() method" )
print ( "The description of the list is : " + api.get_list(list_id = list_id).description)
new_description = "This list is to test the Twitter API."
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)
|
Output :
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.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...