Getting started with the full-archive Tweet counts     endpoint

This quick start guide will help you make your first request to the full-archive Tweet counts endpoint using Postman, a graphical tool that alows you to make 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

The full-archive Tweet counts endpoint is currently available as part of the Academic Research product track only. In order to use this endpoint, you must apply for access to the Academic Research product track

In addition to you being approved, you will have need to have a set of keys and tokens, which you can generate by following these steps:

  • Navigate to your academic research Project in the developer portal and make sure you have an associated developer App within that project.
  • Navigate to the associated developer App's “Keys and tokens” page, and save your API Keys, Access Tokens, and Bearer Token to your password manager.

 

Steps to build a full-archive 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 > Full-archive 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 full-archive Tweet counts endpoint, you must authenticate your request with an OAuth 2.0 Bearer Token.

First, from within the Full-archive 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 full-archive 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 full-archive Tweet counts endpoint


Step four (optional): Specify the granularity and time period

If you click the ‘Send’ button after step three, you will get the default full-archive Tweet counts: by hour for the last 30 days. If you want to get full-archive Tweet counts by day, you will have to add the granularity parameter with a value of day. If you want Tweet counts for more than 30 days ago, you will have to specify the start_time and end_time parameters with the desired values. 

In Postman, navigate to the "Params" tab and add the following key:value pair to the "Query Params" table:

Key

Value

Description

granularity

day

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

start_time

2021-05-01T00:00:00Z

The oldest UTC timestamp from which the Tweets will be provided

end_time

2021-06-01T00:00:00Z

The oldest UTC timestamp from which the Tweets will be provided.


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

      https://api.twitter.com/2/tweets/counts/all?query=from%3ATwitterDev&start_time=2021-05-01T00:00:00Z&end_time=2021-06-01T00:00:00Z&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 a response similar to the following:

      {
   "data": [
       {
           "end": "2021-05-02T00:00:00.000Z",
           "start": "2021-05-01T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-03T00:00:00.000Z",
           "start": "2021-05-02T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-04T00:00:00.000Z",
           "start": "2021-05-03T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-05T00:00:00.000Z",
           "start": "2021-05-04T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-06T00:00:00.000Z",
           "start": "2021-05-05T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-07T00:00:00.000Z",
           "start": "2021-05-06T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-08T00:00:00.000Z",
           "start": "2021-05-07T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-09T00:00:00.000Z",
           "start": "2021-05-08T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-10T00:00:00.000Z",
           "start": "2021-05-09T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-11T00:00:00.000Z",
           "start": "2021-05-10T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-12T00:00:00.000Z",
           "start": "2021-05-11T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-13T00:00:00.000Z",
           "start": "2021-05-12T00:00:00.000Z",
           "tweet_count": 6
       },
       {
           "end": "2021-05-14T00:00:00.000Z",
           "start": "2021-05-13T00:00:00.000Z",
           "tweet_count": 1
       },
       {
           "end": "2021-05-15T00:00:00.000Z",
           "start": "2021-05-14T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-16T00:00:00.000Z",
           "start": "2021-05-15T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-17T00:00:00.000Z",
           "start": "2021-05-16T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-18T00:00:00.000Z",
           "start": "2021-05-17T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-19T00:00:00.000Z",
           "start": "2021-05-18T00:00:00.000Z",
           "tweet_count": 1
       },
       {
           "end": "2021-05-20T00:00:00.000Z",
           "start": "2021-05-19T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-21T00:00:00.000Z",
           "start": "2021-05-20T00:00:00.000Z",
           "tweet_count": 8
       },
       {
           "end": "2021-05-22T00:00:00.000Z",
           "start": "2021-05-21T00:00:00.000Z",
           "tweet_count": 1
       },
       {
           "end": "2021-05-23T00:00:00.000Z",
           "start": "2021-05-22T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-24T00:00:00.000Z",
           "start": "2021-05-23T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-25T00:00:00.000Z",
           "start": "2021-05-24T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-26T00:00:00.000Z",
           "start": "2021-05-25T00:00:00.000Z",
           "tweet_count": 1
       },
       {
           "end": "2021-05-27T00:00:00.000Z",
           "start": "2021-05-26T00:00:00.000Z",
           "tweet_count": 1
       },
       {
           "end": "2021-05-28T00:00:00.000Z",
           "start": "2021-05-27T00:00:00.000Z",
           "tweet_count": 1
       },
       {
           "end": "2021-05-29T00:00:00.000Z",
           "start": "2021-05-28T00:00:00.000Z",
           "tweet_count": 2
       },
       {
           "end": "2021-05-30T00:00:00.000Z",
           "start": "2021-05-29T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-05-31T00:00:00.000Z",
           "start": "2021-05-30T00:00:00.000Z",
           "tweet_count": 0
       },
       {
           "end": "2021-06-01T00:00:00.000Z",
           "start": "2021-05-31T00:00:00.000Z",
           "tweet_count": 0
       }
   ],
   "meta": {
       "total_tweet_count": 22
   }
}
    


Step six: Paginate through your results

If the ‘meta’ object in your response also contains next_token, you can pass its value to the next_token query parameter.

Key Value Description
next_token You will add the next_token that you pull from your previous request's meta object and add it here. If your latest request does not deliver the remainder of the results, you will receive a next_token in the meta object. You will pull the value of that field and add it as the value of the next_token parameter in your next request, holding all other request parameters constant. 

Once you have the right value for next_token set, hit the "Send" button and you will receive the next page of results.

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.