The Twitter API allows you to analyze the organic performance of Tweets by giving you the ability to see a series of metrics associated with a given Tweet. This can be helpful in making data-driven decisions around how specific Tweets are performing. Tweet lookup is a GET method that returns information about a Tweet or group of Tweets. Metrics are available as part of the Tweet lookup endpoint.
In this tutorial, you will learn how to:
- Determine what questions you are trying to solve for
- Connect and authenticate to the Twitter API
- Decide what data you need and make a GET request
- Add in any additional logic needed to answer the question you are trying to solve
Steps to consider
Step 1: Determine what questions you are trying to solve for
In order to measure Tweet performance, you may want to take a moment to determine what you are looking for while analyzing data. This may be a hypothesis you are trying to prove or disprove, a problem you are trying to look deeper into, or a question you are attempting to learn the answer of.
Examples of questions you can ask are:
- Do Tweets with positive sentiment scores perform better than Tweets with negative sentiment scores?
- Which type of language resonates the best with my audience?
- Are my recent Tweets performing below or above my personal average?
- What were the top 10 Tweets of the year from our organization?
Step 2: Connect and authenticate to the Twitter API
In order to connect to the Twitter API, you first will need to authenticate by passing in your credentials before you can get any data back. In order to do so, you should use a library to help you with OAuth.
You will want to make sure to store your credentials in a secure way. Some options include using environment variables or setting up a configuration file that you can store in your .gitignore file on GitHub. You can learn more about authentication and read more about security best practices.
Step 3: Decide what data you need and make a GET request
The data returned in your GET request is determined by the fields and expansions you include in your request. You will want to consider how many Tweets you want to learn more about and determine if it’s a single Tweet or multiple Tweets. Public metrics are what is available for all Tweets whereas non-public metrics are only available for your own or authorized accounts. Public and non-public fields return the sum of organic metrics which are posted and viewed in a regular manner on Twitter and promoted which are posted and viewed as part of an Ads campaign. Additionally, if you are looking for public or non-public metrics around media and engagement, identify what fields the data you are looking for is located in. Metrics that are available include impressions, retweets, quote Tweets, likes, URL link clicks, user profile clicks, replies, video views, and video view quartiles. Learn more about what is available with the API reference guide for Tweet lookup.
An example of a cURL request to a single Tweet is: