2017-06-06 82 views
0

需要使用tweepy
進口tweepy 進口時間reteive retweeters ID,JSON檢索retweeters ID

APP_KEY="" 
APP_SECRET="" 
OAUTH_TOKEN="" 
OAUTH_TOKEN_SECRET="" 

auth = tweepy.OAuthHandler(APP_KEY,APP_SECRET) 
auth.set_access_token(OAUTH_TOKEN,OAUTH_TOKEN_SECRET) 

api = tweepy.API(auth) 
'''for status in api.user_timeline(screen_name='acmigdtuw',include_rts=1,count=200): 
    print status.id''' 
firstTweet = api.user_timeline(screen_name="acmigdtuw")[0] 
print firstTweet.text 
print firstTweet.id 
#results = api.retweets(status.id,cursor=-1,stringify_ids=1) 
pl = api.retweets.id(id=firstTweet.id) 
print pl[0]['user']['screen_name'] 
+0

嘗試'PL = api.retweets(firstTweet.id)'即下 - 最後一線。然後將最後一行更改爲'print pl'將打印'862193390158532608' – davedwards

+0

thankx @downshift回覆:實際上我想打印所有retweeters的id,我如何實現這一點?請幫助...我試過你的解決方案,它給了我詳細的細節。 – vasu

回答

0
firstTweet = api.user_timeline(screen_name="acmigdtuw")[0] 

# get the original tweet 
original_tweet = firstTweet.retweeted_status.id 

# iterate over retweets to get user id 
for status in api.retweets(original_tweet): 
    print status.user.id 

輸出:

839110314012598272 
390229046 

這些都是用戶的ID誰推動原來的推文。

我們可以通過銳推的數目作比較,我們的研究結果證實:

print firstTweet.retweeted_status.retweet_count == len(api.retweets(original_tweet)) 

+0

哇,最後邏輯是在原來的鳴叫... @downshift你提升了我。謝謝很多先生...你再次拯救了生命:) thanx – vasu