2013-01-03 54 views
1

我对python和Twython(我们可以从twitter中检索推文)的概念很陌生。获取在twitter上关注某人的所有用户

使用

from twython import Twython 
twitter=Twython() 
user_timeline=twitter.getUserTimeline(screen_name="bjkbh") 

现在我检索鸣叫我得到所需的鸣叫,但现在我想知道有多少人在下列特定用户。

在微博,我们可以来认识的人通过

for tweets in user_timeline: 

tweets['followers_count'] 

但如何让所有的人以下的名字和他们施加的影响下计数?

谢谢

回答

2

您可以使用两种不同的方法;一个只返回追随者ID(getFollowersIDs),另一个返回追随者集合(getFollowersStatus)的状态/ etc。

一一些示例代码将是这样的:

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关键参数,因此您可以传递给参数的方法与您在文档中找到的方法相同。

+0

喜为answr萨班谢谢,但是当我在做什么,按您的建议,我有以下错误 .PRINT“ID为%d的用户是继ryanmcgrath”%follower_id ....: -------------------------------------------- ------------------------------- TypeError Traceback(最近呼叫的最后一个) /home/vishal/() 1 for follower_id in followers: ----> 2 print“ID为%d的用户是foll由于ryanmcgrath“%follower_id TypeError:%d格式:需要一个数字,而不是unicode – Uselesssss

0

试试这个:

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 
+0

如果帐户拥有超过5000个用户,该怎么办?这是行不通的! – dave

相关问题