Python – API.create_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.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 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)
name = "tweepy_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.
name = "tweepy_list"
description = "A Tweepy list"
mode = "private"
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
Share your thoughts in the comments
Please Login to comment...