Video uploads via REST API

media
video

#1

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.

We are excited to announce that we are now able to offer support for larger, chunked uploads of media (video) via an addition to the REST API.

You can learn more about how this works via our developer blog post. In addition, we have updated the REST API documentation with examples of how this works, and we have also provided information on how to use twurl, our command-line API client, to add video and post Tweets with video embedded.

We are excited to see how you integrate video upload with your applications. Tweet to @TwitterDev with #TwitterVideo and a link to your project!


Video uploads in the REST API
pinned #2

#3

Glad to see this added, some quick questions/requests.

Any best practices/suggestions on chunk sizes?
Do chunks have to be uploaded sequentially?
Can we get the 15MB (and maybe 30 sec) limits added to 1.1/help/configuration.json?


#4

This is great news. I’m having a problem with the chunking though.

So if I upload a single chunk and finalise and add to media_ids on statuses/update.json it all works fine.

However if I upload multiple chunks I get an error, so here’s the logic

WORKING:

  1. Init -> get media_id
  2. Append segment 0 -> get 204 status code
  3. Finalize -> get valid json back
  4. Post to statuses/update with the media_id, post succeeds

BREAKS:

  1. Init -> get media_id
  2. Append segment 0 -> get 204 status code
  3. Append segment 1 -> get 204 status code
  4. Finalize -> get valid json back

{“media_id_string”:“601737201186152448”,“expires_after_secs”:3600,“media_id”:601737201186152448,“size”:1124814,“video”:{“video_type”:“video/mp4”}}

  1. Call statuses/update.json with the media_id as the first example. Get a 400 bad request status code back.

Basically I get a 400 bad request to update.json for all media uploads that use multiple segments but not with a single segment. Any ideas?


#5

I’ve seen this in testing. Can you retry the post with the media attachment after a few moments? I suspect the media is not quite “ready” on the server when you try to do the status update.

… which would lead you to ask, “how long should I wait”, and I don’t have an answer to that at the moment.


#6

We will work on that, I don’t have that info at the moment.

Yes.

That would make sense, I can’t tell you when it will happen though.


#7

Thanks @andypiper I’ll put a short delay into the logic and see if that helps


#8

Also the max upload size in 1.1/help/configuration.json also still shows 3Mb rather than 5Mb


#9

Even waiting for 20 seconds after uploading the last chunk still returns in ‘The validation of media ids failed.’


#12

I’m finding this error exists even with a single APPEND chunk. If I upload a 1.5Mb video it’ll work fine with or without a delay. Upload a single chunk of a file, lets say 3.4Mb and even with a few second delay posting to /statuses/update.json with throw a 400 error

FINALIZE returns

{
    "expires_after_secs" = 3600;
    "media_id" = 602393985588559872;
    "media_id_string" = 602393985588559872;
    size = 3385225;
    video =     {
        "video_type" = "video/mp4";
    };
}

update.json returns

{"errors":[{"code":324,"message":"The validation of media ids failed."}]} status 400

#13

Thanks, Richard. I’m going to pull all of these responses together into a report for the team to look into. Appreciate your feedback and patience as we roll out this feature!


#14

Thanks @andypiper. Looking forward to implementing this :slight_smile:


#15

Hi @andypiper Do you happen to have any update on this. I’m still seeing this problem with larger videos


#16

Not yet - working on circling back with the team - bear with us please! :+1:


#18

Can we use this in Android / iOS to upload the videos? Or is it only for web / desktop apps?


#19

You can use this in Android or iOS, but there are currently no methods inside Fabric to enable you to handle the upload - you’ll have to call the REST API directly.


#20

With reference to https://dev.twitter.com/twitter-kit/android/twitter it is given that TwitterCoreKit can be used for Rest API access but TwitterCoreKit is accessed by using Fabric . But you said Fabric don’t have methods now to upload videos. Then How can we use this upload feature in Android?


#22

Ok, I can’t upload any video that bigger than one chunk.
half of time I receive "The validation of media ids failed."
and the other half
{“https://upload.twitter.com/1.1/media/upload.json?command=FINALIZE&media_id=614813042992390145 web request failed.”}
Internal Server Error - Something is broken. Please post to the group so the Twitter team can investigate.
As a vigilant citizen, I’m reporting it.


#23

Hi, I tried to upload video but failed in the last FINALIZE step. Can anyone pls help? Thanks

INIT --> successful --> return media ID
APPEND --> return 204
FINALIZE --> Error 3 Request failed: internal server error (500)

the finalize command:
command=FINALIZE&media_id=615795891862016000


#25

Hello,

I’m working on an android app that must to be able to send videos to Twitter.
The app is consuming the REST API via Retrofit, overriding some Fabric’s classes.
There are 3 steps to upload a video and 2 of them are working properly
INIT, APPEND - OK
The last step (FINALIZE) is always returning a BAD REQUEST (HTTP 400) response, the parameters are being sent correctly

After all these tips that all of you wrote above, didn’t work.

PLEASE, could any of you, help me?