tweepy如何从id获取用户名

时间:2014-06-07 18:32:21

标签: python tweepy

如何通过tweepy从用户ID号中删除明文用户名?

以下是我正在使用的正确代码:

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

我评论的最后一行是给我一个问题。请指教。谢谢大家!

1 个答案:

答案 0 :(得分:9)

您正在迭代ids,而i已包含ids的元素。尝试将i传递给lookup_users

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

更新,请尝试以下方式:

users = api.lookup_users(user_ids=ids)
for u in users:
    print u.screen_name