DEV Community

Suhem Parack
Suhem Parack

Posted on

Whats new with the Twitter API v2 in 2022

When the Twitter API v2 had just gone public in August 2020, I had made a video (available here) with the technical overview of the new features and functionality available in v2. Since then, there have been quite a few good updates available for developers and researchers in the Twitter API v2. In this post, I will share some of my favorites features and functionality that are available in the Twitter API v2, and why I think developers and researchers should give it a try!

Full-archive search

My favorite feature in the Twitter API v2 is the support for full-archive search. This feature (available only in the academic research product track) lets researchers search for Tweets from the full-archive of public Tweets for free. In v1.1, developers and researchers could only search for Tweets from the last 7 days for free. To use the full-archive search, they had to use the paid premium API. So the full-archive search in v2 enables researchers to study topics from the past for their research studies for free. Learn more about full-archive search here.

Tweet Counts

When you use the search endpoints, you get the Tweets (ID, text etc.) that match a search query. However, in some cases (e.g. for building visualizations) you may just want to know the volume of Tweets on Twitter for a certain topic for a given time period. The Twitter API v2 supports the Tweet counts endpoint that gives you the volume of Tweets for a search query so that you can understand trends and patterns for a topic and build graphs and visualizations for it. The response from these endpoints for a search query looks something like this:

[
      {
        "end": "2021-07-02T00:00:00.000Z",
        "start": "2021-07-01T22:57:15.000Z",
        "tweet_count": 1
      },
      {
        "end": "2021-07-03T00:00:00.000Z",
        "start": "2021-07-02T00:00:00.000Z",
        "tweet_count": 36
      },
      {
        "end": "2021-07-04T00:00:00.000Z",
        "start": "2021-07-03T00:00:00.000Z",
        "tweet_count": 9
      },
      {
        "end": "2021-07-05T00:00:00.000Z",
        "start": "2021-07-04T00:00:00.000Z",
        "tweet_count": 4
      }
    ]
Enter fullscreen mode Exit fullscreen mode

As you can see, instead of the Tweets, this endpoint returns the Tweet volume for a time period. This guide showcases how you can use this Tweet counts endpoint to build visualizations in Python.

Ability to get the full conversation with Quote Tweets and Conversation Threads

The Twitter API v2 supports the Quote Tweets endpoint that gives you all the Quote Tweets for a Tweet. Additionaly, the search endpoints support the conversation_id operator that lets you easily get all the replies to a Tweet. Thus, using these two endpoints, you can get and understand the entire conversation around a Tweet. The Twitter API v1.1 did not support a Quote Tweets endpoint or a conversation_id search operator, thus getting the entire conversation required some custom coding. This guide explains how you can lookup and understand the entire conversation around a Tweet in Python.

Support for Tweet Edits metadata

Since October 2022, the Twitter API v2 supports metadata for edited Tweets. Using the Twitter API v2, you can get a list of revisions to a Tweet as well as information such as how many edits remaining for a Tweet, how much more time left for a Tweet to be edited etc. as shown below:

{
  "edits_remaining": "5",
  "is_edit_eligible": true,
  "editable_until": "2022-09-30T18:30:01.000Z"
}
Enter fullscreen mode Exit fullscreen mode

This guide showcases how to analyze edited Tweets with the Twitter API v2 in Python.

Batch compliance solution

The Twitter Developer API policy requires developers and researchers to keep their Tweet & User datasets in compliance. The Twitter API v2 supports a batch compliance solution that lets developers and researchers upload millions of Tweet or User IDs in bulk and get the current status of those Tweet and User IDs i.e. which of these Tweets are now deleted, suspended etc. or which of these user accounts went from public to protected, so that you can take action on your side. The response from this endpoint looks somethign like this:

{
  "id": "1265324480517361664",
  "action": "delete",
  "created_at": "2019-10-29T17:02:47.000Z",
  "redacted_at": "2020-07-29T17:02:47.000Z",
  "reason": "deleted"
}
Enter fullscreen mode Exit fullscreen mode

This tells us that the Tweet with ID 1265324480517361664 was deleted. This guide showcases how to work with the batch compliance solution in Python.

Context Annotations

The Twitter API v2 supports a cool feature called context annotations. Context annotations provide contextual information about a Tweet and named entity recognition for entities present in a Tweet. There are two components to context annotations:

  • Domain: that is the topic about which a Tweet is
  • Entity: that is any named entity present in a Tweet

So for example, a Tweet about the Los Angeles Lakers may contain context annotations like:

[
  {
    "context": "12.706083845846597632",
    "entity_name": "Los Angeles Lakers"
  },
  {
    "context": "26.706083889454813185",
    "entity_name": "NBA"
  },
  {
    "context": "131.706083902411055104",
    "entity_name": "Basketball"
  }
]
Enter fullscreen mode Exit fullscreen mode

This information tells us that this Tweet is contextually about Basketball, NBA, Lakers etc. Learn more about context annotations here.

Bookmarks

Finally, the Twitter API v2 supports the ability for developers to work with Bookmarks for an authenticated user. You can get, create or delete Bookmarks for an authenticated user. This functionality does not exist in the Twitter API v1.1. Check out this app that showcases this functionality and how a user can export their Twitter bookmarks to Notion.

I hope that some of these features sound exciting to you and that you will give the Twitter API v2 a try! If you have any questions or feedback, feel free to reach out to me on Twitter

Oldest comments (0)