Getting started with the recent Tweet counts endpoint

This quick start guide will help you make your first request to the recent Tweet counts endpoint using Postman, a graphical tool that allows you to send HTTP requests.

If you would like to see sample code in different programming languages, please visit our Twitter API v2 sample code GitHub repository. 

 

Prerequisites

For you to be able to complete this guide, you will have need to have a set of keys and tokens, which you can generate by following these steps:

 

Steps to build a recent Tweet counts request

Step one: Start with a tool or library

There are several different tools, code examples, and libraries that you can use to make a request to this endpoint, but we are going to use the Postman tool here to simplify the process.

To load Twitter API v2 Postman collection into your environment, please click on the following button:


Once you have the Twitter API v2 collection loaded in Postman, navigate to the Tweet counts > Recent Tweet counts request.


Step two: Authenticate your request

To properly make a request to the Twitter API, you need to verify that you have permission to do so. To do this with the recent Tweet counts endpoint, you must authenticate your request with OAuth 2.0 Bearer Token.

First, from within the Recent Tweet counts request in Postman, navigate to the “Authentication” tab. In the "Type" dropdown, select "Bearer Token", and then copy and paste your Bearer Token from your password manager into the "Token" field.

 

Step three: Create a query

Each recent Tweet counts request requires a single query. For this example, we are going to use a query that matches on Tweets posted by the @TwitterDev account. For this query we use the from: operator and set it to TwitterDev (case insensitive):

from:TwitterDev

In Postman, navigate to the "Params" tab and enter this ID, or a string of Tweet IDs separated by a comma, into the "Value" column of the ids parameter.

Key Value Description
query from:TwitterDev Query to submit to the recent Tweet counts endpoint

 

Step four (optional): Specify the granularity of the request

If you click the ‘Send’ button after step three, you will get the default recent Tweet counts: by hour for the last seven days. If you want to get recent Tweet counts by day, you will have to add the granularity parameter with a value of day.

In Postman, navigate to the "Params" tab and day into the "Value" column of the granularity parameter.

Key Value Description
granularity day

The granularity for the Tweet counts results. Possible values are day, hour or minute


You should now see the following URL next to the "Send" button:

      https://api.twitter.com/2/tweets/counts/recent?query=from%3ATwitterDev&granularity=day
    


Step five: Make your request and review your response

Once you have everything set up, hit the "Send" button and you will receive the following response:

      {
   "data": [
       {
           "end": "2021-06-16T00:00:00.000Z",
           "start": "2021-06-15T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-06-17T00:00:00.000Z",
           "start": "2021-06-16T00:00:00.000Z",
           "tweet_count": 1
       },
       {
           "end": "2021-06-18T00:00:00.000Z",
           "start": "2021-06-17T00:00:00.000Z",
           "tweet_count": 2
       },
       {
           "end": "2021-06-19T00:00:00.000Z",
           "start": "2021-06-18T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-06-20T00:00:00.000Z",
           "start": "2021-06-19T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-06-21T00:00:00.000Z",
           "start": "2021-06-20T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-06-22T00:00:00.000Z",
           "start": "2021-06-21T00:00:00.000Z",
           "tweet_count": 1
       },
       {
           "end": "2021-06-23T00:00:00.000Z",
           "start": "2021-06-22T00:00:00.000Z",
           "tweet_count": 2
       }
   ],
   "meta": {
       "total_tweet_count": 6
   }
}
    
Was this document helpful?
Thank you

Thank you for the feedback. We’re really glad we could help!

Thank you for the feedback. How could we improve this document?
Thank you for the feedback. Your comments will help us improve our documents in the future.