【问题标题】:Fetching all the users who are following certain person on twitter获取在 Twitter 上关注某个人的所有用户
【发布时间】:2013-01-03 07:32:35
【问题描述】:

我对 python 和 Twython(我们可以使用它从 twitter 检索推文的库)的概念不熟悉。

现在我正在使用

检索推文
from twython import Twython
twitter=Twython()
user_timeline=twitter.getUserTimeline(screen_name="bjkbh")

我收到了想要的推文,但现在我想知道有多少人在关​​注特定用户。

在推文中我们可以知道关注的人数

for tweets in user_timeline:

tweets['followers_count']

但是我如何获得所有关注的人的名字和他们施加的影响?

谢谢

【问题讨论】:

    标签: python twitter social-networking twython


    【解决方案1】:

    您可以使用两种不同的方法;一种只返回关注者 ID (getFollowersIDs),另一种返回关注者集的状态/等 (getFollowersStatus)。

    一些示例代码如下所示:

    from twython import Twython
    
    twitter = Twython()
    followers = twitter.getFollowersIDs(screen_name = "ryanmcgrath")
    
    for follower_id in followers:
       print "User with ID %d is following ryanmcgrath" % follower_id
    

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

    【讨论】:

    • 嗨 sapan 感谢您的回答,但是当我按照您的建议进行操作时,出现以下错误。打印“ID 为 %d 的用户正在关注 ryanmcgrath”% follower_id ....: -- -------------------------------------------------- ------------------------------------ TypeError Traceback (最近一次调用最后一次) /home/vishal/ in ( ) 1 for follower_id in follower: ----> 2 print "User with ID %d is follow ryanmcgrath" % follower_id 3 TypeError: %d format: a number is required, not unicode
    【解决方案2】:

    试试这个:

    from twython import Twython
    
    twitter = Twython()
    followers = twitter.getFollowersIDs(screen_name = "ryanmcgrath")
    followers = followers['ids']
    print "The user rayanmcgrath has %s followers" % str(len(followers))
    for follower_id in followers:
       print "User with ID %d is following ryanmcgrath" % follower_id
    

    【讨论】:

    • 如果帐户有超过 5000 个用户怎么办。这行不通!
    猜你喜欢
    • 2017-03-03
    • 2018-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多