Monday, November 18, 2024
Google search engine
HomeLanguagesPython – API.update_list() in Tweepy

Python – API.update_list() 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.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 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)


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.




# 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)


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.

Last Updated :
10 Jun, 2020
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments