Twitter defines its platform as "what's happening in the world and what people are talking about right now."
You've got to be on Twitter to understand the strength of this statement. According to the company's Q3 2020 report, 187 million people use the platform daily and 330 million use it at least once a month.
The amount of data that can be generated by such a large population is enough to make any forward-thinking marketer interested in accessing Twitter's API.
Luckily, that's not impossible, nor is it difficult. However, to maximize the use of it, you have to understand how to apply these insights to your business.
But first, it’s worth understanding why marketers are so interested in accessing the Twitter API.
What is the Twitter API?
The Twitter API lets you read and write Twitter data. Thus, you can use it to compose tweets, read profiles, and access your followers’ data and a high volume of tweets on particular subjects in specific locations.
This bridges the gap between the two applications (the one on your phone and the company's software) while providing an extra layer of security. For instance, whenever you use a social media application, you interact with an API. Without direct contact between each other, any potential threats posed by one to the other are abated.
An API also provides a list of commands that can be executed. To use a popular analogy, imagine you're ordering food at a restaurant. You're at the table, ordering from the kitchen. The link between you and the kitchen is the waiter who ensures that the kitchen staff gets all the orders and meals are delivered to the right customers. You're also free to ask them what's available before making your order.
Without the waiter, you'd be pushing your way into the kitchen yourself, trying to get something to eat. That’s where the API plays its role as the middle man between two pieces of software.
The API provides a list of methods the two applications can use to communicate. They include:
- GET for retrieving data.
- POST for creating data.
- PUT for updating data.
- DELETE for removing data.
Twitter API HTTP Methods and Endpoints
As an example, let’s take a look at the methods you would use to post, retrieve, and engage with Tweets.
The Twitter API uses two HTTP methods for retrieving Tweet data: GET and POST.
Be careful: these endpoints will look different depending on what you want to do, so be sure to check the documentation.
For example, if you want to retrieve a Tweet timeline, the endpoints will look as follows:
Features of the Twitter API
Aside from the endpoints, let’s take a look at some of the salient features of Twitter's API:
- There are four main objects: Tweets, Entities, Places, and Users.
- There are daily restrictions: Calls and changes in the API are restricted by access tokens to protect the platform from abuse.
- It is based on HTTP (rather than SSL).
- There are specific measures to adapt the API operation to the social network including library restrictions, generated paging, and specific parameters.
How much does the Twitter API cost?
The Twitter API comes in three subscription packages: Standard, Premium, and Enterprise. Standard is completely free and comes with all the features you need to start using the Twitter API.
If you’re looking for more functionality, such as access to Twitter’s full archive, you’d want to go for a Premium subscription. The Enterprise tier is best for those who want to use Twitter data to offer campaign management or Twitter management services to other businesses.
What can you do with the Twitter API?
You can do a wide variety of things that relate to retrieving, viewing, sorting, and filtering any data on Twitter.
For example, you can:
- Build an app where users can access specific types of Tweets, such as a COVID-related Tweet tracker or a timeline of Tweets that only come from major SaaS organizations.
- Create a website where users can see and read Tweets from certain locations only.
- Launch a personal project to examine the sentiment of your own Tweets.
- Curate certain Tweets to create a story or narrative on your website, for any purpose — to show a trend, demonstrate user engagement with one of your branded hashtags, and more.
Ready to get started? Let’s go over how you can use Twitter’s API step-by-step.
How to Get the Twitter API
- Open a command prompt terminal.
- Open a Twitter Developer account.
- Install Ruby, then launch Twurl.
- Create an API key.
- Authorize your Twitter app and account.
Here’s what this process looks like, in detail:
1. Open a command prompt terminal.
Before installing anything, make sure you're familiar with how to open a terminal.
On Mac: Go to Finder > Applications > Utilities > Terminal. Alternatively, open Spotlight by pressing CMD + Space and search for "terminal".
On Windows: Open Command Prompt by going to Start and searching for "cmd".
Microsoft stopped mainstream support for Windows 7 in January 2020. But if you're on that or older, use Start > All Programs > Accessories > Command Prompt.
2. Open a Twitter Developer account.
To proceed, you need to have a Twitter developer account. To create one, open the apps management page and create an app. Name it, enter a website URL, and give a 100-word description.
3. Install Ruby, then launch Twurl.
To run Twurl, you'll need Ruby. So, make sure to have it installed. Then, follow Twitter's tutorials to install Twurl.
4. Create an API key.
To send API calls, Twitter assigns a unique set of keys to your developer account. To access them, login to your developer account and select Details from your apps management screen.
Click on Keys and Tokens to generate a new, unique, and secret API key. Copy the secret and consumer API keys.
5. Authorize your Twitter app and account.
Run the following command in your terminal to authorize your Twitter app and account:
Note: replace <key> and <secret> with your API keys.
Finally, copy and paste the returned URL to your browser to get a PIN. Then, enter the PIN into your terminal.
You're all set now. For more information, check out Twitter's guidelines on authentication.
Once you access the Twitter API, you'll be able to perform user activities, such as sending messages and media without having to open the application. By using command-line tools like Twurl and cURL, you’ll find more efficiency than you would by using the application directly.
How to Use the Twitter API
- Send a tweet.
- Upload a media file.
- Respond to a tweet.
- Retrieve tweets under a specific hashtag.
- Find locally trending subjects.
- Create bots.
Using a command-line tool, you can use your access to the Twitter API to perform a wide range of tasks. Twurl is one of the best tools for this job. It's built like cURL but has been modified specifically for the Twitter API.
Run the twurl -h command to learn more about using Twurl. For a simple tutorial, run twurl -T or twurl --tutorial.
Then, when you’re ready, below are some ideas for how to use the Twitter API.
Send a tweet.
You can use your new set up to send a tweet using the statuses/update POST endpoint. Twitter’s documentation says this "updates the authenticating current user's status" (i.e. sends a tweet).
Upload a media file.
Using Twurl, you can also upload:
- Images up to 5MB
- GIFs up to 15MB
- Videos up to 15MB
Use the media/upload endpoint as follows:
Respond to a tweet.
To respond to a tweet, use the status/update POST endpoint, just as you would to send a fresh tweet.
Retrieve tweets under a specific hashtag.
To retrieve all tweets with a specific hashtag, use the search/tweets GET endpoint. By default, the results return tweets sent in the previous seven days.
You can use this function to evaluate a past marketing campaign — yours or that of another company. With access to all the tweets shared under a particular hashtag, you can learn a lot about your target audience, including the general mood around the topic.
Find locally trending subjects.
Find out what people in your locale are buzzing about. Use the trends/place GET endpoint. You'll need to provide the Yahoo! Where On Earth ID (WOEID) for your location — use WOEID Lookup to find yours.
Once you know the trending subjects for your audience, you can decide how to use the discussions to promote your brand.
Create bots.
If you want to venture deeper into the world of the Twitter API, you can use all of these and other endpoints to create bots. Then, they can share specific content, show live updates about a particular topic, and remind your staff and followers of an event — among other things.
G2 shares a useful resource to get your feet wet with Twitter bots.
Now, let’s take a look at some Twitter API examples so that you can see how it all applies in the real world.
Twitter API Examples
- TweetBot
- Twitter’s TweetDeck
- Tweetmap
- Birdie for Twitter
- Twitterrific
- Chirp for Twitter
- Tweetagram
1. TweetBot
TweetBot, created by Tapbots, uses Twitter’s API to provide a seamless, ad-free experience for Twitter users. The timeline is also chronological rather than algorithm-based, and you can make private notes on people’s profiles, a feature not currently offered by Twitter.
TweetBot uses the following functionalities:
- Post, retrieve, and engage with Tweets
- Retrieve Tweet timelines
- Filter real-time tweets
- Send and read direct messages
2. Twitter’s TweetDeck
TweetDeck once used to be a separate property from Twitter, but was acquired by the social media giant in 2011. While it’s inseparable from its parent brand, TweetDeck is worth mentioning because it uses the Twitter API to function as a dashboard with full functionality.
What makes it different? You can see notifications, tweets, and trending topics all at the same time. Additionally, you can change the columns for a completely personalized experience.
TweetDeck uses all of the Twitter API functionalities. You can publish Tweets, create collections, send DMs, and more through this web app.
3. Tweetmap
OmniSci’s Tweetmap is one of a handful of web apps that shows location-based Tweets. This web app can be used to determine which hashtags are trending where.
Tweetmap uses the following functionalities:
4. Birdie for Twitter
Birdie for Twitter is a one-of-a-kind app that combines both news articles and Tweets from reputable news sources. You can read news articles within this app after clicking on a link on your timeline.
Birdie for Twitter uses the following functionalities:
5. Twitterrific
Twitterrific is for those who get overwhelmed by the sheer volume of information and Tweets in the original Twitter app. You can mute hashtags, phrases, and words. Like in the TweetBot app, the timeline is also chronological, and there are no sponsored tweets.
Twitterrific uses the following functionalities:
- Post, retrieve, and engage with Tweets
- Filter real-time tweets
- Follow, search, and get users
- Search Tweets
- Get Tweet timelines
6. Chirp for Twitter
Chirp for Twitter is an Apple Watch app that’s specifically designed for use on the device’s small screen. Currently, you can post and read Tweets, as well as view and send direct messages.
Chirp for Twitter uses the following functionalities:
- Post, retrieve, and engage with Tweets
- Send and read direct messages
- Follow and search users
- Search Tweets
7. Tweetagram by Bannerbear
Tweetagram is a handy tool for creating graphics out of notable Tweets. Simply input the link of a Tweet, and the tool will create several graphics for you to choose from:
Tweetagram uses the following functionality:
These are only a few of the examples of real-world Twitter API use cases. Twitter also has a list of partners who use its APIs to offer Twitter marketing, analytics, and data management services. If you’re an agency or SaaS business, Twitter APIs could help you develop a new offering for your customers.
Use Twitter APIs to Grow Your Brand
You can use Twitter APIs to build an app that your customers will love or strengthen your Twitter engagement efforts. Overall, Twitter is a great place to communicate with and learn from your audience. With access to the Twitter API, you can finetune your marketing through in-depth customer (and even competitor) analysis.
Editor's note: This post was originally published in March 2020 and has been updated for comprehensiveness.