skip to Main Content

Is there any way to get the comment/reply count for a tweet using GET statuses/user_timeline in addition to favorite_count and retweet_count which are already returned?

Thanks!

3

Answers


  1. This feature had been requested since 2011 but there are no public API for reply counts so far, so it’s not possible to directly get the reply count of a tweet.


    But there exists a workaround using the Search API:

    You can do the query: q = "to:{author_screen_name}", sinceId = {tweet_id}, while author_screen_name is the screen name (like ‘shiftpsh’ in @shiftpsh) and tweet_id is id of the tweet you’re trying to get the reply count.

    Loop through all the tweets in the results and filter which in_reply_to_status_id_str is {tweet_id}.

    Keep in mind that the Standard Search API has a search index limit of 7 days (30 days if premium) so the resulting reply count can be not accurate.

    Login or Signup to reply.
  2. Twitter still doesn’t have a sound solution for this.

    Similar to shiftpsh’s answer, with Node you can make a query to https://twitter.com/${screen_name}/status/${tweet_id} and use a module like JSDOM in JavaScript to parse the HTML into a DOM object. With that object, you can use normal document querying functions to pull out the reply count (and many other data points).

    var repliesCount = parseInt(document.getElementsByClassName("permalink-tweet-container")[0]
        .getElementsByClassName("ProfileTweet-action--reply")[0]
      .getElementsByClassName("ProfileTweet-actionCount")[0]
      .getAttribute("data-tweet-stat-count"));
    

    This solution is a form of web scraping, so please be responsible when employing these types of solutions.

    EDIT: Just noticed your tags are for Java, jsoup is a great library for parsing HTML to an object and traversing it with jQuery like methods.

    Login or Signup to reply.
  3. Just thought I’d update this answer for anyone who’s facing the issue.
    Twitter’s API now includes "metrics" endpoint where you can get this information.

    Following the documentation:

    "GET /tweets/metrics/private supports the ability to retrieve Tweet engagement data and delivers the following metrics:

    • impressions
    • Retweets
    • Quote Tweets
    • likes
    • replies
    • video views
    • video view quartiles
      "

    The caveat, however, is that it only applies to owned or authorised accounts and tweets posted in the previous 30 days (before the request)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search