tweepy how to get a username from id

☆樱花仙子☆ 提交于 2019-12-08 18:04:24

问题


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!


回答1:


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


来源:https://stackoverflow.com/questions/24100377/tweepy-how-to-get-a-username-from-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!