Please note:
We recently released new Tweet lookup and user lookup endpoints into Twitter API v2: Early Access.
Learn more about the new functionality at the following links:
- Tweet lookup and its migration guide
- User lookup and its migration guide
Interested in exploring Labs?
The endpoints we release in Labs are previews of tools that may be released more broadly in the future, but will likely undergo changes before then. We encourage you to take that into consideration as you explore. Before getting started, please read more about Twitter Developer Labs.
Getting started with the GET /tweets endpoint
The GET /tweets endpoint provides developers with public Tweet data for requested available Tweets. The response includes Tweet objects in JSON format. A Tweet object contains public Tweet metadata such as id, text, created_at, lang, source, public_metrics and more. To learn more about data returned in the Tweet object, check out the "Response fields" section in the API reference or our guide on the new fields parameter.
In the following quick start guide, we will request this specific Tweet from @TwitterDev and specify a set of fields desired for the response, including one expansion for media to get additional media fields.
There are a few methods for sending requests to the users endpoint. In order to access the GET /tweets endpoint, you will need the following:
- An approved developer account
- A registered app
- Activate the “Tweets and Users” preview in the Labs dashboard
Authentication
All the endpoints in this preview are authenticated using OAuth 2.0 Bearer Token (also known as application-only authentication). This means you will need to generate a Bearer Token, and pass this token in all of your requests. Once configured, our Postman collection will handle the generation of a Bearer Token for you. Other clients like curl and Insomnia will require you to generate a token manually.
REST Client
REST applications such as Postman can be used for organizing, testing, and debugging HTTP requests.
We have compiled a collection of example requests to all Twitter Developer Labs endpoints, including the GET /tweets endpoint. Postman provides a user-interfaces for managing authentication, setting request headers, working with request parameters, and examining response JSON.
You can get started with a Labs collection by reading our "Getting started with Postman" tutorial and clicking on the following button:
Accessing the Tweets API
The example requests below will return a specific Tweet from @TwitterDev
These examples illustrate the basic mechanics of the endpoint, making an authenticated request and displaying the response, but are not well suited for real-world use. One reason is that they work directly with hard-coded consumer keys and secrets, instead of loading credential tokens from another resource. Another reason is that they make a single request and stop.
These and other scripts are available in our Labs Sample Code repository.
- cURL
- Twurl
- Python 3
- Ruby
- JavaScript (Node.js)
Tweet response
The response for the Tweets request shown above will look like the JSON payload below.
{
"data": {
"attachments": {
"media_keys": [
"7_1138489597158199298"
]
},
"author_id": "2244994945",
"context_annotations": [
{
"domain": {
"id": "45",
"name": "Brand Vertical",
"description": "Top level entities that describe a Brands industry"
},
"entity": {
"id": "781974596165640193",
"name": "Technology"
}
},
{
"domain": {
"id": "46",
"name": "Brand Category",
"description": "Categories within Brand Verticals that narrow down the scope of Brands"
},
"entity": {
"id": "781974596752842752",
"name": "Services"
}
},
{
"domain": {
"id": "47",
"name": "Brand",
"description": "Brands and Companies"
},
"entity": {
"id": "10045225402",
"name": "Twitter"
}
}
],
"created_at": "2019-06-11T17:59:13.000Z",
"entities": {
"annotations": [
{
"start": 44,
"end": 65,
"probability": 0.3687,
"type": "Product",
"normalized_text": "Twitter Developer Labs"
}
],
"urls": [
{
"start": 174,
"end": 197,
"url": "https://t.co/eNx4Wc3Qwj",
"expanded_url": "https://twittercommunity.com/t/twitter-developer-labs-is-open-to-all-developers/126717",
"display_url": "twittercommunity.com/t/twitter-deve…",
"images": [
{
"url": "https://pbs.twimg.com/news_img/1198608207737806848/EPekNT6H?format=jpg&name=orig",
"width": 1200,
"height": 630
},
{
"url": "https://pbs.twimg.com/news_img/1198608207737806848/EPekNT6H?format=jpg&name=150x150",
"width": 150,
"height": 150
}
],
"status": 200,
"title": "Twitter Developer Labs is open to all developers",
"description": "Following our initial announcement, we’re excited to share that Twitter Developer Labs is now available to all developers! Twitter Developer Labs is a new program to let developers test new API endpoints and share feedback as we build the new generation of the Twitter API. Since the endpoints we will release in Labs are early previews, they may change before we release them broadly. We encourage you to take that into consideration as you build with them. For example, this might mean they’re not...",
"unwound_url": "https://twittercommunity.com/t/twitter-developer-labs-is-open-to-all-developers/126717"
},
{
"start": 198,
"end": 221,
"url": "https://t.co/ucmZrJAYjk",
"expanded_url": "https://twitter.com/TwitterDev/status/1138505981460193280/video/1",
"display_url": "pic.twitter.com/ucmZrJAYjk"
}
]
},
"id": "1138505981460193280",
"lang": "en",
"public_metrics": {
"retweet_count": 107,
"reply_count": 31,
"like_count": 258,
"quote_count": 36
},
"source": "Twitter Web Client",
"text": "🎺 da-dada-DAH! We’re introducing the first Twitter Developer Labs endpoints: \n\n✨GET/users and GET/tweets ✨\n\nLabs is now open to all developers to start experimenting today 👉 https://t.co/eNx4Wc3Qwj https://t.co/ucmZrJAYjk"
},
"includes": {
"media": [
{
"media_key": "7_1138489597158199298",
"type": "video"
}
]
}
}
Additional resources
- Learn more about the new Developer Labs on the "About Labs" page.
- Learn more about What’s new.
- Dive into our documentation on Tweets and Users.
- Check out our API reference to learn more about what’s available.
- Give feedback on Twitter Developer Labs.
- Tell us about your experience using the Twitter Developer Labs endpoints by filling out this survey.