REST API now supports native video upload

By Jon Bulava

In January, we launched native video uploads for our mobile applications. Today, we are extending this ability to developers looking to deliver rich video content via Twitter.

Videos are some of the most exciting and engaging content on Twitter. Since the first day that Twitter users could upload 30-second videos, developers have been asking about being able to do so via the Twitter API. Today, we’re excited to provide both API access for video uploads and a protocol to enable chunked uploads. Uploading video presents unique challenges due to file sizes, connection speeds, and a variety of devices. Chunked uploads enables a file to be uploaded in pieces. We’ve published guidelines to assist you with integrating this functionality into your solutions. You’ll also notice an update on the media/upload documentation page.

The code below demonstrates how the video above was uploaded and Tweeted using twurl.

split -b 5m video_launch.mp4

twurl -H upload.twitter.com "/1.1/media/upload.json" -d "command=INIT&media_type=video/mp4&total_bytes=6634737" {"media_id":601491637433475073,"media_id_string":"601491637433475073","expires_after_secs":3599}

twurl -H upload.twitter.com "/1.1/media/upload.json" -d "command=APPEND&media_id=601491637433475073&segment_index=0" --file ./xaa --file-field "media"

twurl -H upload.twitter.com "/1.1/media/upload.json" -d "command=APPEND&media_id=601491637433475073&segment_index=1" --file ./xab --file-field "media"

twurl -H upload.twitter.com "/1.1/media/upload.json" -d "command=FINALIZE&media_id=601491637433475073" {"media_id":601491637433475073,"media_id_string":"601491637433475073","size":6634737,"expires_after_secs":3600,"video":{"video_type":"video\/mp4"}}

twurl "/1.1/statuses/update.json" -d "status=We are excited to announce that the REST API now supports native video upload. https://blog.twitter.com/2015/rest-api-now-supports-native-video-upload&media_ids=601491637433475073"

There are a few items to keep in mind when uploading video:

  • The maximum file size is 15MB and is checked during the upload process
  • The maximum length is 30 seconds and is checked when Tweeting with a video media_id
  • One video (or animated GIF) media_id can be added to a Tweet. Photos are the only media type that can be added up to four times.

We are excited to see how you integrate video upload with your applications. Tweet to @TwitterDev with #TwitterVideo and a link to your project, and we’ll highlight a few in a future post.