Reputation: 281
I want to see the list of my followers in Instagram by python. I write this code
from InstagramAPI import InstagramAPI
username="*******"
InstagramAPI = InstagramAPI(username, "******")
InstagramAPI.login()
InstagramAPI.getProfileData()
followers = InstagramAPI.getTotalSelfFollowers()
print (followers[0])
It works fine and show
{u'username': u'yasinyasinyasinl', u'has_anonymous_profile_picture': True, u'profile_pic_url': u'https://instagram.fevn1-1.fna.fbcdn.net/vp/19319123fc5a0016b6fd518cfa7058ce/5D7C0DF1/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=instagram.fevn1-1.fna.fbcdn.net', u'full_name': u'yasin', u'pk': 5580539929, u'is_verified': False, u'is_private': True}
I want to get all the keys I try
for a,b in followers[0]:
print (followers[0].keys())
But it did not work. What should I do?
and
print (followers[0].get(username))
None
Upvotes: 0
Views: 285
Reputation: 1510
Guessing from your question, I take it that followers
is a list
with dict
elements.
This means that followers[0]
will be a single dict containing the information for one of your followers. If you want to display that username, just fetch it without a loop using followers[0]['username']
.
If you want to display all your followers, loop over the list
instead:
for follower in followers:
print(follower['username'])
Extra hint: know that you can easily get a list
of your follower's usernames using Python's beautiful list comprehension: [follower['username'] for follower in followers]
.
Hope this help!
Upvotes: 2