Python – Tweepy 中的 API.blocks()
Twitter是一个流行的社交网络,用户在其中分享称为推文的消息。 Twitter 允许我们使用 Twitter API 或Tweepy挖掘任何用户的数据。数据将是从用户那里提取的推文。首先要做的是从 Twitter 开发人员那里轻松获得每个用户可用的消费者密钥、消费者秘密、访问密钥和访问秘密。这些密钥将帮助 API 进行身份验证。
API.blocks()
Tweepy 模块中API
类的blocks()
方法用于获取被认证用户阻止的所有用户的列表。
Syntax : API.blocks()
Parameters : None
Returns : a list of objects of class User
示例 1:使用blocks()
方法查找经过身份验证的用户阻止的用户数。
# 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)
# getting the blocked users
blocked_users = api.blocks()
# printing the number of blocked users
print(len(blocked_users))
输出 :
63
示例 2:使用blocks()
方法查找被认证用户阻止的所有用户的屏幕名称。
# getting the blocked users
blocked_users = api.blocks()
# printing the screen names of the blocked users
for user in blocked_users:
print(user.screen_name)
输出 :
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
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。