Open In App

Python – API.create_list() in Tweepy

Last Updated : 10 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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.create_list()

The create_list() method of the API class in Tweepy module is used to create a list.

Syntax : API.create_list(name, mode, description)

Parameter :

  • name : name of the list.
  • url : mode of the list, either public or private, defaults to public.
  • description : description of the list.

Returns : an object of class List

Example 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)
  
# name of the list
name = "tweepy_list"
  
# creating the list
list = api.create_list(name)
  
print("Name of the list : " + list.name)
print("Number of members in the list : " + str(list.member_count))
print("Mode of the list : " + list.mode)


Output :

Name of the list : tweepy_list
Number of members in the list : 0
Mode of the list : public

Example 2 : Using the create_list() method with the parameters mode and description.




# the name of the list
name = "tweepy_list"
  
# the description of the list
description = "A Tweepy list"
  
# the mode of the list
mode = "private"
  
# creating the list
list = api.create_list(name, description = description, mode = mode)
  
print("Name of the list : " + list.name)
print("The description of the list : " + str(list.description))
print("Mode of the list : " + list.mode)


Output :

Name of the list : tweepy_list
The description of the list : A Tweepy list
Mode of the list : private


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads