Open In App

Python – API.blocks_ids() in Tweepy

Last Updated : 08 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.blocks_ids()

The blocks_ids() method of the API class in Tweepy module is used to get a list of all the users IDs of the users blocked by the authenticated user.

Syntax : API.blocks_ids()

Parameters : None

Returns : a list of Integers

Example 1 : Finding the number of users blocked by the authenticated user using the blocks_ids() method.




# 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_ids()
  
# printing the number of blocked users
print(len(blocked_users))


Output :

63

Example 2 : Finding the user IDs of all users blocked by the authenticated user using the blocks_ids() method.




# getting the blocked users
blocked_users = api.blocks_ids()
  
# printing the user IDs of the blocked users
for IDs in blocked_users:
    print(IDs)


Output :

28406270
292558545
705807268835672064
65851020
1246402093851856896
1492538024
323599188
130557513
1082334352711790593
167272426
101311381
147994804
419107960
256999501
108577950
1432374242
715401445785210880
1187330941
46062566
236826818
706044393749417984
1120868702298066945
90346496
16485058
4316769252
3242292793
594785338
68399705
189917061
1130956814567260161
990908549768200192
900223598144757763
963800904540540928
2289518994
922564729
3220084519
952841063273709568
16948493
380749300
841712647246614531
3305945622
101494182
129731515
784682859286130689
132385468
2583217418
2455275793
762299610765271040
772180779640033281
826117446050381826
2097571
826091183491387394
826099053788327936
338444460
232193350
392608775
891250296512323585
2247560024
2835317718
804006430063759360
2982269822
792319459759386624
80876565


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads