Getting started with the Tweet lookup endpoints

This quick start guide will help you make your first request to the Tweet lookup endpoints with a set of specified fields using Postman.

If you would like to see some code samples in different languages, please visit the GET /tweets API Reference page

 

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:

  1. Apply for a developer account and receive approval.
  2. If you already have a developer account, activate the new developer portal.
  3. Create a Project and an associated developer App in the developer portal.
  4. Navigate to your app's “Keys and tokens” page, and save your API Keys, Access Tokens, and Bearer Token to your password manager.

 

Steps to build a GET /tweets 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 GET /tweets endpoint.
 

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 GET /tweets endpoint, you must pass your developer App's Bearer Token along with your request.

First, from within the GET /tweets 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: Identify and specify which Tweets you would like to retrieve

You must specify a Tweet or a set of Tweets that you would like to receive within the request. You can find the Tweet ID by navigating to twitter.com and clicking on a Tweet, and then looking in the URL. For example, the following URL's Tweet ID is 1228393702244134912.

https://twitter.com/TwitterDev/status/1228393702244134912

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
ids 1228393702244134912,1227640996038684673,1199786642791452673

 

Step four: Identify and specify which fields you would like to retrieve

If you click the "Send" button after step three, you will receive the default Tweet object fields in your response: id and text.

If you would like to receive additional fields beyond id and text, you will have to specify those fields in your request with the field and/or expansion parameters.

For this exercise, we will request a three additional different sets of fields from different objects:

  1. The additional tweet.created_at field in the primary user objects.
  2. The associated authors’ user object’s default fields for the returned Tweets: id, name, and username
  3. The additional  user.created_at field in the associated user objects.
     

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

Key Value Returned fields
tweet.fields created_at tweets.created_at
expansions author_id includes.users.id, includes.users.name, includes.users.username
user.fields created_at includes.users.created_at

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

  https://api.twitter.com/2/tweets?ids=1228393702244134912,1227640996038684673,1199786642791452673&tweet.fields=created_at&expansions=author_id&user.fields=created_at


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": [
    {
      "author_id": "2244994945",
      "created_at": "2020-02-14T19:00:55.000Z",
      "id": "1228393702244134912",
      "text": "What did the developer write in their Valentine’s card?\n  \nwhile(true) {\n    I = Love(You);  \n}"
    },
    {
      "author_id": "2244994945",
      "created_at": "2020-02-12T17:09:56.000Z",
      "id": "1227640996038684673",
      "text": "Doctors: Googling stuff online does not make you a doctor\n\nDevelopers: https://t.co/mrju5ypPkb"
    },
    {
      "author_id": "2244994945",
      "created_at": "2019-11-27T20:26:41.000Z",
      "id": "1199786642791452673",
      "text": "C#"
    }
  ],
  "includes": {
    "users": [
      {
        "created_at": "2013-12-14T04:35:55.000Z",
        "id": "2244994945",
        "name": "Twitter Dev",
        "username": "TwitterDev"
      }
    ]
  }
}

Was this document helpful?

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.