Developers

Understand Build on Tap into
what's happening.

Publish and analyze Tweets, optimize ads, and create unique customer experiences.

Migrate to v8 of the Twitter Ads API.

Start with a use case

Listen & analyze

Learn from the public conversation to inform decisions.

Advertise

Programmatically create and manage Twitter ad campaigns.

Publish & curate

Tell great stories with Twitter content.

Engage

Create connections with conversational experiences.

Explore what’s possible

The following examples demonstrate how Twitter developer products can be used to build solutions across a diverse set of use cases. Preview the data that is returned by our endpoints.

  • Listen & analyze
  • Advertise
  • Publish & curate
  • Engage
Search historical Tweets

Analyze Tweets based on contextual, implicit topics or keywords.

EXAMPLE REQUEST

      # Looking for Tweets that are not Retweets from @sandboxpark, 
# a phrase "sea turtles" or a hashtag #seaturtleweek. Returned data includes
# the original conversation Tweet ID, publicly shown metrics and annotated 
# context from Twitter’s own machine learning models. 

GET https://api.twitter.com/2/tweets/search/recent
     query=(from:sandboxpark OR @attributeisland OR "sea turtles" OR #seaturtleweek)-is:retweet
     tweet.fields=public_metrics,context_annotations,conversation_id
    

EXAMPLE RESPONSE

      {
	"data": [{
			"id": "1278450000060131444",
			"text": "Road tripping this summer? Here is a guide of passes to purchase and places to stay. https://t.co/RGZIwCOWSG",
			"conversation_id": "1278450000060131444",
			"public_metrics": {
				"retweet_count": 2,
				"reply_count": 0,
				"like_count": 4,
				"quote_count": 1
			},
			"context_annotations": [{
					"domain": {
						"id": "65",
						"name": "Interests and Hobbies Vertical",
						"description": "Top level interests and hobbies groupings, like Food or Travel"
					},
					"entity": {
						"id": "839159814991167489",
						"name": "Travel",
						"description": "Travel"
					}
				},
				{
					"domain": {
						"id": "66",
						"name": "Interests and Hobbies Category",
						"description": "A grouping of interests and hobbies entities, like Novelty Food or Destinations"
					},
					"entity": {
						"id": "839160129752686593",
						"name": "General Travel",
						"description": "General Travel"
					}
				},
				{
					"domain": {
						"id": "67",
						"name": "Interests and Hobbies",
						"description": "Interests, opinions, and behaviors of individuals, groups, or cultures; like Speciality Cooking or Theme Parks"
					},
					"entity": {
						"id": "849076092111536128",
						"name": "Adventure travel",
						"description": "Adventure travel"
					}
				},
				{
					"domain": {
						"id": "67",
						"name": "Interests and Hobbies",
						"description": "Interests, opinions, and behaviors of individuals, groups, or cultures; like Speciality Cooking or Theme Parks"
					},
					"entity": {
						"id": "839161975712067584",
						"name": "Travel Actions",
						"description": "This entity includes all conversations about travel and vacation."
					}
				}
			]
		},
		{
			"id": "1280169000000704333",
			"text": "@attributeisland @iterationjoe What beautiful creatures! Happy #seaturtleweek",
			"conversation_id": "1279940000004973111",
			"public_metrics": {
				"retweet_count": 0,
				"reply_count": 0,
				"like_count": 0,
				"quote_count": 0
			}
		},
		{
			"id": "1280166000000519222",
			"text": "@attributeisland \"One touch of nature makes the whole world kin.\" -John Muir",
			"conversation_id": "1279940000004973111",
			"public_metrics": {
				"retweet_count": 0,
				"reply_count": 1,
				"like_count": 1,
				"quote_count": 0
			}
		},
			{
			"id": "1279940000004973111",
			"text": "Sea turtles are roaming in our waters!",
			"conversation_id": "1279940000004973111",
			"public_metrics": {
				"retweet_count": 67,
				"reply_count": 11,
				"like_count": 396,
				"quote_count": 2
			},
			"context_annotations": [{

					"domain": {
						"id": "65",
						"name": "Interests and Hobbies Vertical",
						"description": "Top level interests and hobbies groupings, like Food or Travel"
					},
					"entity": {
						"id": "852262932607926273",
						"name": "Pets",
						"description": "Pets"
					}
				},
				{
					"domain": {
						"id": "66",
						"name": "Interests and Hobbies Category",
						"description": "A grouping of interests and hobbies entities, like Novelty Food or Destinations"
					},
					"entity": {
						"id": "852638925591949314",
						"name": "Reptiles",
						"description": "Reptiles"
					}
				},
				{
					"domain": {
						"id": "67",
						"name": "Interests and Hobbies",
						"description": "Interests, opinions, and behaviors of individuals, groups, or cultures; like Speciality Cooking or Theme Parks"
					},
					"entity": {
						"id": "852658483748941824",
						"name": "Turtles",
						"description": "Turtles"
					}
				}
			]
		}
],
	"meta": {
		"newest_id": "1278450000060131444",
		"oldest_id": "1279940000004973111",
		"result_count": 10,
		"next_token": "b26v89c19zqg8o3fo7gg1ye94q1e4k5dkjhwf8pojy5q5"
	}
}
    
Ready to build with recent search?
Ads API

Create a new Twitter Ads campaign.

EXAMPLE REQUEST

      # Create a new Campaign:

twurl -H ads-api.twitter.com -X POST "/2/accounts/hkk5/campaigns?funding_instrument_id=hw6ie&total_budget_amount_local_micro=5500000&daily_budget_amount_local_micro=500000&start_time=2013-01-01T00:00:01Z&entity_status=PAUSED&name=Launch"
    

EXAMPLE RESPONSE

      "data": {
    "name": "Launch",
    "start_time": "2013-01-01T00:00:01Z",
    "reasons_not_servable": [
      "PAUSED_BY_ADVERTISER",
      "INCOMPLETE"
    ],
    "servable": false,
    "daily_budget_amount_local_micro": 500000,
    "end_time": null,
    "funding_instrument_id": "hw6ie",
    "duration_in_days": null,
    "standard_delivery": true,
    "total_budget_amount_local_micro": 5500000,
    "id": "9bo81",
    "entity_status": "PAUSED",
    "account_id": "hkk5",
    "frequency_cap": null,
    "currency": "USD",
    "created_at": "2017-08-21T23:01:20Z",
    "updated_at": "2017-08-21T23:01:20Z",
    "deleted": false
  }
    
Ready to build with the Twitter Ads API?
Embed a Tweet

Embed a Tweet on your website.

EXAMPLE REQUEST

      # Fetch any embeddable Twitter object from the oEmbed API


let oembedResponse = await fetch(new Request('https://publish.twitter.com/oembed?url=https://twitter.com/jack/status/20'));
let oembedTweet = oembedResponse.json();

# Make a request to the oEmbed API

{
  "url": "https://twitter.com/jack/status/20",
  "author_name": "jack",
  "author_url": "https://twitter.com/jack",
  "html": "<blockquote class=\"twitter-tweet\"><p lang=\"en\" dir=\"ltr\">just setting up my twttr</p>&mdash; jack (@jack) <a href=\"https://twitter.com/jack/status/20\">March 21, 2006</a></blockquote>\n<script async src=\"//platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>",
  "width": 550,
  "height": null,
  "type": "rich",
  "cache_age": "3153600000",
  "provider_name": "Twitter",
  "provider_url": "https://twitter.com",
  "version": "1.0"
}

    

EXAMPLE RESPONSE

      # This returns a JSON oEmbed response

<article>
  <figure>
    {{{oembedTweet.html}}}
    <figcaption>Tweet by Jack Dorsey</figcaption>
  </figure>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p>
</article>

# Output the HTML into your page.
    
Ready to build with Twitter for Websites?
Account Activity API

Programatically manage Twitter actions on behalf of a Twitter user.

SET UP

      # Receive events for the subscribed users via webhook delivery:
{
	"for_user_id": "4337869000",
	"direct_message_events": [{
		"type": "message_create",
		"id": "954491830116151111",
		"created_timestamp": "1516403560557",
		"message_create": {
			"target": {
				"recipient_id": "4337869000"
			},
			"sender_id": "3001961111",
			"source_app_id": "129032",
			"message_data": {
				"text": "Rocky Breakpoint National Park",
				"entities": {
					"hashtags": [],
					"symbols": [],
					"user_mentions": [],
					"urls": []
				}
			}
		}
	}],
	"apps": {
		"129032": {
			"id": "129032",
			"name": "Twitter for iPhone",
			"url": "http://twitter.com/download/iphone"
		},
		"users": {},
		"4337869000": {
			"id": "4337869000",
			"created_timestamp": "1422556069340",
			"name": "the SnowBot",
			"screen_name": "SnowBotDev",
			"location": "Boulder, CO",
			"description": "#TwitterBot built by @snowman",
			"url": "https://t.co/SnxaA15ZuY",
			"protected": false,
			"verified": false,
			"followers_count": 154,
			"friends_count": 37,
			"statuses_count": 494,

		},
		"3001961111": {
			"id": "3001961111",
			"created_timestamp": "1448312972328",
			"name": "Refactor Rena",
			"screen_name": "refactorrena",
			"location": "Oakland, CA",
			"protected": false,
			"verified": false,
			"followers_count": 8,
			"friends_count": 8,
			"statuses_count": 240,
		}
	}
}

    

RESPOND

      # Reply programmatically to Direct Messages.

POST https://api.twitter.com/1.1/direct_messages/events/new.json
    -data {
	     "event": {
		     "type": "message_create",
		      "message_create": {
		     	    "target": {
				   "recipient_id": "3001961111"
			     },
			     "message_data": {
				   "text": "Rocky Breakpoint National Park:\n* Last snow: 3\", 2 days ago\n* Accumulated depth at the base: 3\'2\"\n* Today\'s high temp is 34 F with winds up to 20 MPH\n* No overnight snow expected","
			     }
		      }
	       }
          }
    
Ready to build the Account Activity API?

Ready to build?

Review the documentation to get started.