如何使用 Twython 获得 Twitter 关注者?

发布于 2024-11-06 19:58:36 字数 71 浏览 0 评论 0原文

当指定用户的屏幕名或 user.id 时,我想获取特定用户的 Twitter 关注者/关注者列表。谁能提供它的代码片段吗?谢谢。

I want to get a list of twitter followers/following of a particular user, when their screenname or user.id is specified. Can anyone please give the code snippet for it? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

往事风中埋 2024-11-13 19:58:36

我是《Twython》的作者。为此,您可以使用两种不同的方法;一种仅返回关注者 ID (get_followers_ids),另一种返回关注者集的状态/等 (get_followers_list)。

一些示例代码如下所示:

from twython import Twython

twitter = Twython()
followers = twitter.get_followers_ids(screen_name = "ryanmcgrath")

for follower_id in followers:
    print "User with ID %d is following ryanmcgrath" % follower_id

如果您有 ID,则需要自己进行进一步查找,因此后一种方法 (get_followers_list) 可能正是您想要的。请记住,Twython 函数只是镜像官方 Twitter API 文档中的 API 关键参数,因此您可以传递给参数的方法与您在文档中找到的方法相同。

祝你好运!

I'm the author of Twython. There's two different methods you can use for this; one that returns just follower IDs (get_followers_ids), and one that returns the statuses/etc of a follower set (get_followers_list).

Some example code for one would be like the following:

from twython import Twython

twitter = Twython()
followers = twitter.get_followers_ids(screen_name = "ryanmcgrath")

for follower_id in followers:
    print "User with ID %d is following ryanmcgrath" % follower_id

If you have IDs, you'd need to do further lookups yourself, so the latter method (get_followers_list) may be what you want. Keep in mind that Twython functions just mirror API key parameters from the official Twitter API docs, so the methods you can pass to an argument are the same as what you'll find on the docs.

Good luck!

难理解 2024-11-13 19:58:36
from twython import Twython

twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

followers = twitter.get_followers_ids(id = 1234) # or just () - followers for your account

print(twitter.get_followers_ids()['ids']) # ids list of followers
from twython import Twython

twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

followers = twitter.get_followers_ids(id = 1234) # or just () - followers for your account

print(twitter.get_followers_ids()['ids']) # ids list of followers
九八野马 2024-11-13 19:58:36

应该是:

followers = twitter.get_followers_list(screen_name = "whatever")

It should be :

followers = twitter.get_followers_list(screen_name = "whatever")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文