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.list_timeline()
The list_timeline()
method of the API
class in Tweepy module is used to fetch timeline of tweets authored by members of the specified list.
Syntax : API.list_timeline(parameters)
Parameters :
- list_id : ID of the list.
- slug : slug of the list.
- owner_id : ID of the owner of the list.
- owner_screen_name : screen name of the owner of the list.
- since_id : minimum limit on the ID of the status.
- max_id : >maximum limit on the ID of the status.
- count : the number of statuses to be fetched.
- include_entities : a boolean to include entity nodes.
- include_rts : a boolean to include retweets.
Returns : a list of objects of class Status
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) # the ID of the list list_id = # fetching all the lists statuses = api.list_timeline(list_id = list_id) # counting the number of statuses fetched print ( "The number of statuses fetched from the list are : " + str ( len (statuses))) |
Output :
The number of statuses fetched from the list are : 17
Example 2 : Only fetching a certain number of statuses using the parameter count.
# the ID of the list list_id = # number of statuses to be fetched count = 3 # fetching all the lists statuses = api.list_timeline(list_id = list_id, count = count) # counting the number of statuses fetched print ( "The number of statuses fetched from the list are : " + str ( len (statuses))) |
Output :
The number of statuses fetched from the list are : 3
<!–
–>
Please Login to comment…