Standard v1.1 compared to Twitter API v2

If you have been working with the v1.1 statuses/sample endpoint, the goal of this guide is to help you understand the similarities and differences between the standard and Twitter API v2 sample stream endpoints.

  • Differences
    • Endpoint URLs
    • Request parameters
    • New JSON format

       

Differences

Endpoint URLs

  • Standard v1.1 endpoints:
    • https://stream.twitter.com/1.1/statuses/sample

  • Twitter API v2 endpoint:
    • https://api.twitter.com/2/tweets/sample/stream


Authentication method

The standard endpoint supports OAuth 1.0a User Context, whereas the new Twitter API v2 sample stream endpoint supports OAuth 2.0 Bearer Token (also referred to as Application-only authentication). To make requests to the Twitter API v2 version you must use a Bearer Token to authenticate your requests.

You can easily obtain a Bearer Token on navigating to your app's “Keys and tokens” page on the developer portal. If you’d like to generate a Bearer Token, see this OAuth 2.0 Bearer Token guide
 

Request parameters

One of the biggest differences between standard v1.1 and Twitter API v2 endpoint versions is how you select which fields return in your payload. For the standard endpoints, there are several parameters that you could use to identify which fields or sets of fields would return in the payload, while the Twitter API v2 version simplifies these different parameters into fields and expansions

  • fields: Twitter API v2 endpoints enable you to select which fields are provided in your payload. For example, Tweet, User, Media, Place, and Poll objects all have a list of fields that can be returned (or not). 

  • expansions: Used to expand the associated objects referenced in Tweet JSON payloads. For example, all Retweets and Replies reference other Tweets. By setting expansions=referenced_tweets.id, these other Tweet objects are expanded according to the tweet.fields setting.  Other objects such as users, polls, and media can also be expanded. 

You can learn more about how to use fields and expansions by visiting our guide, and by reading through our broader data dictionary.

There are also a set of standard v1.1 request parameters not supported in Twitter API v2:

Standard v1.1 parameter

Details

Delimited

With the v1.1 endpoint, setting this to the string length indicates that statuses should be delimited in the stream, so that clients know how many bytes to read before the end of the status message.

This functionality is not available with Twitter API v2

Stall_warnings

With the v1.1 endpoint, setting this parameter to the string true will cause periodic messages to be delivered if the client is in danger of being disconnected. 

With Twitter API v2, stall warnings are sent by default with the new line sent every so often. 


New JSON format

Twitter API v2 is introducing new JSON designs for the objects returned by the APIs, including Tweet and user objects.

  • At the JSON root level, the standard endpoints return Tweet objects in a statuses array, while Twitter API v2 returns a data array. 
  • Instead of referring to Retweeted and Quoted "statuses", Twitter API v2 JSON refers to Retweeted and Quoted Tweets. Many legacy and deprecated fields, such as contributors and user.translator_type are being removed. 
  • Instead of using both favorites (in Tweet object) and favourites (in user object), Twitter API v2 uses the term like
  • Twitter is adopting the convention that JSON values with no value (for example, null) are not written to the payload. Tweet and user attributes are only included if they have a non-null values. 
     

In addition to the changes that we made to our new JSON format, we also introduced a new set of fields to the Tweet object including the following:

  • conversation_id
  • Two new annotations fields, including context and entities
  • Several new metrics fields 

Was this document helpful?

Thank you for the feedback. We’re really glad we could help!

Thank you for the feedback. How could we improve this document?

Thank you for the feedback. Your comments will help us improve our documents in the future.