Twitter特定帐户以下列表
这是我的代码。我能为此获得200多人。我对API不了解。要获得结果,我必须做出什么变化(我正在检查的帐户有15000个关注者)
user = api.get_user(screen_name='Calendly')
data = \[x.\_json for x in tweepy.Cusor(user.followers(count=200)).item(200)\]
df = pd.DataFrame(data)
df = df\[\['id', 'name', 'screen_name'\]\]
df.to_csv('followers.csv', index=False)
This is my code.How can i get more than 200 person with this.I have no idea about APIs.What changes i have to make to get my result (the account i was checking had 15000 followers)
user = api.get_user(screen_name='Calendly')
data = \[x.\_json for x in tweepy.Cusor(user.followers(count=200)).item(200)\]
df = pd.DataFrame(data)
df = df\[\['id', 'name', 'screen_name'\]\]
df.to_csv('followers.csv', index=False)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您提供的代码中有一些错别字。
此外,您正在使用哪个版本的Twitter API?
我要假设这是1.1,因为您使用光标。
一些备注:
光标(count = ...)
参数是每页获得 的最大关注者数量。项目(...)
参数是总计的最大关注者数量。因此,您将无法获得200多个关注者
,将其设置为200。但是,您将不得不处理Twitter速率限制(此端点的每15次剪辑的15个请求)。独自处理异常,或使用
wait_on_rate_limit
参数初始化API时(但是如果帐户有15000个关注者,则需要一些时间)。一个非常基本的示例:
请注意,我没有使用列表理解可读性,但请随时这样做。
There are a few typos in the code you provided.
Moreover, which version of the Twitter API are you using?
I am going to assume that this is the 1.1 because you use Cursor.
A few remarks:
The
Cursor(count=...)
argument is the maximum number of followers to get per page.The
items(...)
argument is the maximum number of followers to get in total.So you can't get more than 200 followers in you set it to 200.
And if you want all the followers, don't set it at all. But you will have to deal with the Twitter rate limits (15 requests per 15 minuts for this endpoint). Handle the exception by yourself or use the
wait_on_rate_limit
argument when you initialise the API (but it will take some time if the account has 15 000 followers).A very basic example:
Please note that I did not use list comprehension for readability, but feel free to do so.