Twitter Video support in REST and Streaming API


#1

Jan 28, 2015 Update: Please read this announcement regarding available video formats.

We’re excited to announce that we are releasing native consumer videos to public. We knew this announcement would raise questions about what would happen with the API. Ultimately, this means we’ll soon be able to render video via Tweets to developers via REST & Streaming API. More details to follow but below is a look at what the new data payload will look like.

Starting in early February, we will begin to roll out support for video rendering across REST and Streaming APIs. More specifically, a new media type of “video” will appear in the “extended_entities” section, and the “video_info” section will contain the following video-related properties:

1. aspect_ratio: The aspect ratio of the video, as a simplified fraction of width and height in a 2-element array. Typical values are [4, 3] or [16, 9]

2. duration_millis: The length of the video, in milliseconds.

3. variants: Different encodings/streams of the video. At least one variant is returned for each video entry. Video formats returned via the API are subject to change. As a best practice, developers should scan all returned values and use the most appropriate format for their given platform.

Additionally, each “variant” object contains the following properties:

1. content_type: The simplified type of the video format, such as video/mp4 or video/webm. We currently support H.264 and WebM for progressive download, and HLS for adaptive streaming.

2. url: The URL to the video file or playlist, depending on the content type.

3. bitrate

For displaying a video preview or thumbnail, developers should use the “media_url” or “media_url_https” values that point to an image. (We have also included photos in the old “entities/media” object for backward compatibility.)

Below is a more complete example of a video entity being returned in “extended_entities” section of a response.

"extended_entities":{
  "media": [
    {
      "display_url": "pic.twitter.com\/31JoMS50ha",
      "expanded_url": "http:\/\/twitter.com\/twitter\/status\/560070183650213889\/video\/1",
      "features": {
        
      },
      "id": 5.6007013197639e+17,
      "id_str": "560070131976392705",
      "indices": [
        110,
        132
      ],
      "media_url": "http:\/\/pbs.twimg.com\/ext_tw_video_thumb\/560070131976392705\/pu\/img\/TcG_ep5t-iqdLV5R.jpg",
      "media_url_https": "https:\/\/pbs.twimg.com\/ext_tw_video_thumb\/560070131976392705\/pu\/img\/TcG_ep5t-iqdLV5R.jpg",
      "sizes": {
        "large": {
          "h": 576,
          "resize": "fit",
          "w": 1024
        },
        "medium": {
          "h": 337,
          "resize": "fit",
          "w": 600
        },
        "small": {
          "h": 191,
          "resize": "fit",
          "w": 340
        },
        "thumb": {
          "h": 150,
          "resize": "crop",
          "w": 150
        }
      },
      "type": "video",
      "url": "http:\/\/t.co\/31JoMS50ha",
      "video_info": {
        "aspect_ratio": [
          16,
          9
        ],
        "duration_millis": 30033,
        "variants": [
          {
            "bitrate": 2176000,
            "content_type": "video\/mp4",
            "url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/vid\/1280x720\/c4E56sl91ZB7cpYi.mp4"
          },
          {
            "bitrate": 320000,
            "content_type": "video\/mp4",
            "url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/vid\/320x180\/nXXsvs7vOhcMivwl.mp4"
          },
          {
            "bitrate": 832000,
            "content_type": "video\/webm",
            "url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/vid\/640x360\/vmLr5JlVs2kBLrXS.webm"
          },
          {
            "bitrate": 832000,
            "content_type": "video\/mp4",
            "url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/vid\/640x360\/vmLr5JlVs2kBLrXS.mp4"
          },
          {
            "content_type": "application\/x-mpegURL",
            "url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/pl\/r1kgzh5PmLgium3-.m3u8"
          }
        ]
      }
    }
  ]
}

Video returned as type "photo" in extended_entities
pinned globally #2

#3

Happy to see public support for this added so quickly after it was released. Will it be possible to post mp4s to the media/upload.json API?


#4

We do not have anything to announce on video upload APIs at this time, but stay tuned to @twitterapi and the forums.


#5

Awesome! Are there any plans to make video view\impressions available as an organic metric available via API?


#6

Currently there are no metrics or analytics APIs so there are no plans, but that could change in the future. Great feedback!


#7

@andypiper are these changes live in the REST API?


#8

Should be in the next couple of weeks - “early February” is the plan for both REST and Streaming.


#9

Thanks …showing up in the API :smile:
But how to play those .mp4 ?

Am fetching it object.extended_entities.media[0].video_info.variants[0].url and usign it inside

<video width="320" height="240" controls>
  <source src="{{object.extended_entities.media[0].video_info.variants[0].url}}" type="video/mp4">
Your browser does not support the video tag.
</video>

But still it’s not showing up :frowning:


#10

Update: It does work for http version of the URL, if our domain doesn’t have https enabled.
Anyway, thanks …

[Both http and https URLs would have been handy.]


#11

video_info JSON Structure

media JSON Structure


#12

Thanks! That is quite nice.


#13

Does this impact any plans to generate a video retention graph?


#14

I’m not familiar with what you’re referring to here, sorry.


#15

@andypiper: I think he is referring to “Audience Retention Report”, so this would be an analytics feature, if I understand it correctly.


#16

Ahh I see - @jameserrico I don’t have any information about a graph feature of that kind.


#17

Did you guys know when the video upload will be available on API ?


#18

Seems there is no schedule yet for this feature.


#19

Hello guys,

Sorry but I’m a bit confused with this topic…

The message from [quote=“pi_kumar, post:1, topic:31258”]
Ultimately, this means we’ll soon be able to render video via Tweets to developers via REST & Streaming API. More details to follow but below is a look at what the new data payload will look like. Starting in early February, we will begin to roll out support for video rendering across REST and Streaming APIs
[/quote]
… tends to prove that the support of videos has been enabled in February.

This is apparently confirmed from users by reading messages from

and

The thing is that I can’t see such extended_entities property when using the REST API console for a tweet having a video. For instance the following REST API call for a tweet with a video doesn’t bring extended_entities - see https://api.twitter.com/1.1/statuses/show/556066244005085184.json?include_entities=true ( https://apigee.com/snapshot/twitter?snapId=apigee-console-snapshots-1422766800000_96c79f2a-7b98-4721-b911-295a4ecb62b7 for the snapshot).

So are Twitter videos supported in the REST API at the moment ? Are there some specific conditions so that videos are returned in the extended_entities using the REST services ?

Thanks a lot for your help,

Alexandre 8)


#20

You are right, the video entity is missing. I am not sure if this is a problem with the API though, as looking at the JSON it seems like the Tweet only includes a link to a Twitter Video which maybe was posted in some other way (?), some clarification would indeed be great…