1

私はpythonとTwython(Twitterからツイートを取得できるライブラリ)の概念に慣れていません。

今、私はツイートを取得しています

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

目的のツイートを取得していますが、特定のユーザーをフォローしている人の数を知りたいと思っています。

ツイートでは、フォローしている人の数を知ることができます

for tweets in user_timeline:

tweets['followers_count']

しかし、フォローしているすべての人々の名前と、彼らが及ぼす影響力をどのように取得すればよいでしょうか?

ありがとう

4

2 に答える 2

2

これに使用できる2つの異なる方法があります。1つはフォロワーIDのみを返すもの(getFollowersIDs)、もう1つはフォロワーセットのステータスなどを返すもの(getFollowersStatus)です。

1つのサンプルコードは次のようになります。

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関数は公式のTwitterAPIドキュメントのAPIキーパラメータをミラーリングしているだけなので、引数に渡すことができるメソッドはドキュメントにあるものと同じであることに注意してください。

于 2013-01-04T14:08:21.143 に答える
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
于 2013-01-11T17:09:47.933 に答える