Python – API.blocks() in Tweepy
Last Updated :
08 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.blocks()
The blocks()
method of the API
class in Tweepy module is used to get a list of all the users blocked by the authenticated user.
Syntax : API.blocks()
Parameters : None
Returns : a list of objects of class User
Example 1 : Finding the number of users blocked by the authenticated user using the blocks()
method.
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)
blocked_users = api.blocks()
print ( len (blocked_users))
|
Output :
63
Example 2 : Finding the screen names of all users blocked by the authenticated user using the blocks()
method.
blocked_users = api.blocks()
for user in blocked_users:
print (user.screen_name)
|
Output :
kumailn
NorbertElekes
fjamie013
Trendulkar
iShivamDubey
KapilSharmaK9
gaywonk
mehdirhasan
Ilhan
Begin_Humor
iamsrk
rishibagree
Turki_alalshikh
ahrefs
devduttmyth
Francesgracella
realshooterdadi
h3h3productions
indiantweeter
AdnanSamiLive
AjitKDoval_FAN
piyushpatriotic
TheSamirAbbas
sonalkalra
MsBlaireWhite
vishal_ketto
fay_alif
vivekoberoi
waglenikhil
AMMARlSE
AyushPa89314914
MSArenaOfficial
DilipVa37961599
sunilku31690409
ViratGang
narendramodi177
katrinakaif_4
tariqnasheed
Apple
HolyKaaba
AisiTaisiDemo
sanjivbhatt
saudipost
arifkhanesm
BeingSalmanKhan
AcharyaPramodk
iAnkurSingh
HinduDharma1
WakeUpHindu
bbcnewstelugu
cnni
bbcnewspunjabi
bbcnewsmarathi
AtheistRepublic
rajshah
Shehzad_Ind
siddaramaiah
FeminismInIndia
RVCJ_FB
MFSahiHai
TheQuint
BilalMadni13
AmbedkarCaravan
Share your thoughts in the comments
Please Login to comment...