Twitter API v2: How to Find the Unknown Unknowns

Avatar

With version 2.0 of the Twitter API possessing a wealth of new features, one of the most useful additions to the social media API are annotations, which offer a way to understand each tweet’s contextual information. Using the new Twitter Recent Search API to turn each search for tweets into a journey of discovery allows you to expand your search vocabulary beyond a single term or phrase—you can now learn even more about the subject you’re browsing.

You can find a variety of requests on the Twitter public workspace:

To get started with the Twitter Recent Search API, head over to the Postman API Network and click on the Run in Postman button for the Twitter API v2 Postman Collection. Once the collection downloads into your Postman on the web or desktop app, you can begin making requests to the Recent Search API or other API path Twitter provides.

Using Postman and the new Twitter Recent Search API
Using Postman and the new Twitter Recent Search API

Twitter API v2 documentation

The documentation for the Twitter API v2 will provide you with everything you need to get up and running with the API. Once you’re set up, you can begin searching and exploring annotations for each response using Postman. When you make a request to v2 of the Recent Search API, you will get back a context_annotation property like this for each tweet returned:

These annotations help you understand more about the context behind each tweet, allowing you to see other hidden dimensions associated with each search you make via the API. There are five types of annotations you will receive associated with each API request you make. Here are some examples of each:

  • Person: Barack Obama, Daniel, or George W. Bush
  • Place: Detroit, Cali, or “San Francisco, California”
  • Product: Mountain Dew, Mozilla Firefox
  • Organization: Chicago White Sox, IBM
  • Other: Diabetes, Super Bowl 50

To understand the potential of tweet annotations, try a search for “2020 election,” making sure you have context_annotations defined as part of your tweet.fields property. Here are some of the annotations you will see returned with a search:

  • Person: Donald Trump, Kyle Griffin, Kanye West, Alexander Marlow, Paul Sperry, Nancy Pelosi, Adam Schiff, Daniel Dale, Chuck Schumer, Hugh Hewitt, Kamala Harris, Cory Gardner, Sarah Huckabee Sanders, Manu Raju, Lindsey Graham, Ruth Bader Ginsburg, Justin Trudeau, Joni Ernst, Jake Tapper, Marsha Blackburn, Eric Trump, Dan Bongino, Mike Pence, Joe Biden, Amy Klobuchar, Mitch McConnell, Andrew Cuomo, Jeff Merkley, Tucker Carlson, Seth Abramson, Susan Collins
  • Politician: Donald Trump, Nancy Pelosi, Adam Schiff, Chuck Schumer, Kamala Harris, Cory Gardner, Sarah Huckabee Sanders, Lindsey Graham, Justin Trudeau, Joni Ernst, Marsha Blackburn, Mike Pence, Joe Biden, Amy Klobuchar, Mitch McConnell, Andrew Cuomo, Jeff Merkley, Susan Collins
  • Journalist: Kyle Griffin, Alexander Marlow, Daniel Dale, Hugh Hewitt, Manu Raju, Jake Tapper, Dan Bongino, Tucker Carlson

With a search of the phrase “2020 election” using the Twitter Recent Search API, you can expand your search vocabulary using the above people, politicians, and journalists. The ability to make more precise searches means you can return more relevant results and more annotations—tailoring your search experience to be as wide or as narrow as you desire.

To quickly aggregate annotations across many different tweets, we use the Postman Visualizer combined with the following test script:

You can paste the above script in as a test script for any request you make to the Twitter Recent Search API in order to easily see all of the domains and entities associated with the tweets. You can also use Postman Visualizer to quickly help you see the unknown unknowns that exist beyond your immediate search—which helps to turn a single Twitter API search into an exploratory journey of relevant topics across Twitter. This builds on top of the machine learning Twitter has employed to help make sense of what is happening across the social media platform.

A winning combo

The pairing of Postman and the Twitter Recent Search API, enhanced with a simple script and the Postman Visualizer, makes for a pretty robust way to discover new relevant topics during your social media exploration. It not only helps find the unknown aspects of any topic or conversation you are searching, but also widens your understanding of what’s going on across the expansive Twitter platform using machine learning. Ultimately, putting Postman to work with the latest version of the Twitter API helps you better dig into the Twitter social media universe and leverage more information that can help drive your business, research, and more.

What do you think about this topic? Tell us in a comment below. You can also give product feedback through our Community forum and GitHub repository.

Comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 thought on “Twitter API v2: How to Find the Unknown Unknowns

  • Avatar

    All ok