Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tweepy how to get a username from id

Tags:

python

tweepy

how do I derrive a plaintext username from a user Id number with tweepy?

Here is the CORRECTED code that I am using:

ids = []
userid = "someOne"
for page in tweepy.Cursor(api.followers_ids, screen_name=userid).pages():
     ids.extend(page)
     time.sleep(60)

print len(ids), "following have been gathered from", userid  

users = api.lookup_users(user_ids=ids)#ieterates through the list of users and prints them
for u in users:
    print u.screen_name

The last line I have commented is the one giving me an issue. Please advise. Thank you all!

like image 301
Kyle Sponable Avatar asked Jun 07 '14 18:06

Kyle Sponable


1 Answers

You are iterating ids and i already contains element of ids. Try to pass i to lookup_users:

for i in ids:
    print screen_name(api.lookup_users(i))
    # print screen_name(api.lookup_users(ids[i]))

update, try this way:

users = api.lookup_users(user_ids=ids)
for u in users:
    print u.screen_name
like image 117
ndpu Avatar answered Sep 19 '22 11:09

ndpu