tweepy 如何从 id 获取用户名 [英] tweepy how to get a username from id
本文介绍了tweepy 如何从 id 获取用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 tweepy 从用户 ID 号导出纯文本用户名?
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!
推荐答案
您正在迭代 ids
并且 i
已经包含 ids
的元素.尝试将 i
传递给 lookup_users
:
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]))
更新,试试这个:
users = api.lookup_users(user_ids=ids)
for u in users:
print u.screen_name
这篇关于tweepy 如何从 id 获取用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文