【问题标题】:get all retweets user-id for each tweet-id获取每个推文 ID 的所有转推用户 ID
【发布时间】:2021-01-27 02:19:22
【问题描述】:

我有一个 ID 超过 100 的推文列表,我想获取每条推文的所有转推 ID 我使用的代码用于一条推文 ID 我如何提供推文 ID 列表并检查是否有转推为这条推文打印用户 ID

# import the module 

import tweepy 

  
# assign the values accordingly 

consumer_key = "" 

consumer_secret = "" 

access_token = "" 

access_token_secret = "" 

  
# authorization of consumer key and consumer secret 

auth = tweepy.OAuthHandler(consumer_key, consumer_secret) 

  
# set access to user's access key and access secret  
auth.set_access_token(access_token, access_token_secret) 

  
# calling the api  

api = tweepy.API(auth) 

  
# the ID of the tweet 

ID = 1265889240300257280

  
# getting the retweeters 

retweets_list = api.retweets(ID) 

  
# printing the screen names of the retweeters 

for retweet in retweets_list: 

    print(retweet.user.screen_name) 

谁能帮帮我?

【问题讨论】:

    标签: python api twitter tweepy


    【解决方案1】:

    要从推文列表中获取转推,您需要遍历推文 ID 列表并依次为每个推文调用 api.retweets 函数。


    如果你的推文本身有超过 100 条转推,你就会遇到 API 的限制。

    根据 Tweepy documentation:

    API.retweets(id[, count])

    最多返回给定推文的前 100 条转发。

    Twitter API 本身仅支持检索最多 100 条转推,请参阅 API documentation(这与 Tweepy 调用的 API 相同):

    获取状态/转推/:id

    返回由 id 参数指定的推文的 100 条最近转发的集合。

    【讨论】:

      【解决方案2】:

      这对我有用:

      for retweet in retweets_list: 
      
          print (retweets_list.retweet_count)
      

      【讨论】:

        猜你喜欢
        • 2016-12-03
        • 1970-01-01
        • 1970-01-01
        • 2014-12-07
        • 1970-01-01
        • 2017-11-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多