Whats new with the Twitter API v2 in 2022
Tags: twitter, api
Published: 2022-10-11 16:56:32

When the Twitter API v2 had just gone public in August 2020, I had made a video (available [here](https://twitter.com/TwitterDev/status/1296493468345413637)) 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](https://developer.twitter.com/en/docs/twitter-api/tweets/search/quick-start/full-archive-search). This feature (available only in the [academic research product track](https://developer.twitter.com/en/products/twitter-api/academic-research)) 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](https://developer.twitter.com/en/docs/twitter-api/premium). 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](https://developer.twitter.com/en/docs/twitter-api/tweets/search/quick-start/full-archive-search).

## Tweet Counts

When you use the [search endpoints](https://developer.twitter.com/en/docs/twitter-api/tweets/search/introduction), 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](https://developer.twitter.com/en/docs/twitter-api/tweets/counts/introduction) 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:

```json
[
      {
        "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
      }
    ]
```

As you can see, instead of the Tweets, this endpoint returns the Tweet volume for a time period. [This guide](https://dev.to/suhemparack/building-visualizations-with-tweet-counts-from-the-twitter-api-v2-in-python-1nb0) 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](https://developer.twitter.com/en/docs/twitter-api/tweets/quote-tweets/introduction) 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](https://dev.to/suhemparack/understanding-the-entire-conversation-around-a-tweet-with-the-twitter-api-v2-3ce6) 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](https://developer.twitter.com/en/blog/product-news/2022/supporting-edit-tweet-functionality). 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:

```json
{
  "edits_remaining": "5",
  "is_edit_eligible": true,
  "editable_until": "2022-09-30T18:30:01.000Z"
}
```

[This guide](https://dev.to/suhemparack/how-to-analyze-edited-tweets-with-the-twitter-api-v2-using-python-odj) showcases how to analyze edited Tweets with the Twitter API v2 in Python.

## Batch compliance solution

The [Twitter Developer API policy](https://developer.twitter.com/en/developer-terms/agreement-and-policy) requires developers and researchers to keep their Tweet & User datasets in compliance. The Twitter API v2 supports a [batch compliance solution](https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/introduction) 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:

```json
{
  "id": "1265324480517361664",
  "action": "delete",
  "created_at": "2019-10-29T17:02:47.000Z",
  "redacted_at": "2020-07-29T17:02:47.000Z",
  "reason": "deleted"
}
```

This tells us that the Tweet with ID `1265324480517361664` was deleted. [This guide](https://dev.to/suhemparack/a-guide-to-working-with-the-batch-compliance-endpoints-in-the-twitter-api-v2-3kid) showcases how to work with the batch compliance solution in Python.

## Context Annotations

The Twitter API v2 supports a cool feature called [context annotations](https://developer.twitter.com/en/docs/twitter-api/annotations/overview). 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:

```json
[
  {
    "context": "12.706083845846597632",
    "entity_name": "Los Angeles Lakers"
  },
  {
    "context": "26.706083889454813185",
    "entity_name": "NBA"
  },
  {
    "context": "131.706083902411055104",
    "entity_name": "Basketball"
  }
]
```

This information tells us that this Tweet is **contextually** about Basketball, NBA, Lakers etc. Learn more about context annotations [here](https://developer.twitter.com/en/docs/twitter-api/annotations/faq).

## Bookmarks

Finally, the Twitter API v2 supports the ability for developers to [work with Bookmarks](https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/introduction) 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](https://twitter-bookmarks-to-notion.glitch.me/) that showcases this functionality and how a user can export their Twitter bookmarks to [Notion](https://www.notion.so/).

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](https://twitter.com/suhemparack)