400 Error trying to use TWTRAPIClient.uploadMedia for videos

video
media-upload

#1

I’m getting a 400 error trying to use for video upload with iOS TwitterKit/TwitterCore 2.6.1:

/**
 *  Uploads media to the media server. Returns a media ID to be used when tweeting.
 *
 *  @param media       The media to upload
 *  @param contentType The HTTP content type of the media that you are uploading.
 *  @param completion  The completion handler to invoke.
 */
open func uploadMedia(_ media: Data, contentType: String, completion: @escaping TwitterKit.TWTRMediaUploadResponseCompletion)

Is video/mp4 the correct contentType? I’ve tried a bunch of others with no success

client.uploadMedia(videoData, contentType: "video/mp4", completion: { mediaId, error in

I’ve also verified my video is acceptable and can be uploaded using this tool that I found in this forum https://django-rest-apis.herokuapp.com/media/video

Any ideas?


#2

Hey @steveholt55,

Are you trying to do a chunked media upload or everything in one feel swoop? Can you also share how large the video is? There’s more information on uploading media here: https://dev.twitter.com/rest/media/uploading-media.html

-Mike


#3

@bonnell - I’m trying to upload the video all at once, no chunking. The uploadMedia function makes no mention of chunks, to me it seems like it should handle it. Is TWTRAPIClient.uploadMedia not intended for videos?

All video sizes are failing, for example I again just tried a video with a size of 319283 bytes. And then trying that same video using this https://django-rest-apis.herokuapp.com/media/video, works.

As a workaround I’m able to use the Twitter API to upload the video (INIT, APPEND,FINALIZE), but it seems like this uploadMedia function should be doing exactly that anyways.


#4

Hi people. I stuck with the same problem :

Error Domain=TWTRNetworkingErrorDomain Code=-1011 "Request failed: bad request (400)" 
UserInfo={NSLocalizedFailureReason=, TWTRNetworkingStatusCode=400, 
NSErrorFailingURLKey=https://upload.twitter.com/1.1/media/upload.json, NSLocalizedDescription=Request failed: bad request (400)} 

my code as simple as it can be:

let client = TWTRAPIClient.withCurrentUser()
do {
     let movieData = try Data(contentsOf:url)
     client.uploadMedia(movieData, contentType: "video/mpeg4-generic", completion: { mediaID, error in
           if (error != nil) {
               print("Tweet composition cancelled:")
               print(error as Any)
           } else {
               print("Sending tweet!")
               print("mediaID: ", mediaID as Any)
           }

     })
} catch {
    return
}

Video taked by iPhone
video duration < 7sec
video size < 8Mb
video dimentions = 1280x720
video bitrate = 900k
video fps = 30 fps
audio = no audio

PS. it loads via media validation tool and inspector

PPS. setting “video/quicktime” - doesnt help


#5

I’m moving this to the Media API category as it’s not Fabric specific and thus will be more likely to get help from folks that are more familiar with this area.


#6

Looking for the same answer.


#7

Would appreciate an update from Twitter staff, too.


#8

it works only for images.
For videos I used chunk upload.


#9

Does this issue still exist? I’m getting the same error in uploading a video. I’ve checked my video is capable for uploading to Twitter.
Or does anybody know about a good helper for chunk uploading?


#10

as stated here 400 Error trying to use TWTRAPIClient.uploadMedia for videos it is only for images


#11

Does Twitter have any plans to add video support to their upload media function? Based on the amount of Stackoverflow issues and people on this thread it is a common use case. Seems unnecessary to have everyone roll their own identical solutions outside the API.


#12

It seems like you’re specifically asking about the Twitter Kit SDK? The API platform roadmap is at https://t.co/roadmap


#13

The roadmap says

Have feedback about what you see here? Looking to share what you’d like to see us working on around our API platform? Visit our developer forums to see what others are saying and join the conversation.

Is there a better place to get the roadmap updated to ensure this feature is included? Should the text on the roadmap be updated if posting here on the forum is not correct?


#14

For Twitter Kit (a library that uses the API), the best approach is to raise an issue or pull request on the Open Source project on Github - in the case of Android and Unity at least - or to request via this category on the forum. At the moment the roadmap is focused on the base platform API. The Twitter media upload API does support video, but Twitter Kit has not implemented this fully at this time.


#15

I’d be happy to raise an issue on github or submit a PR! Can you post a link to the project on github? Twitter github objective-c projects doesn’t include twitterkit, nor does the cocoapod link to the github page.


#16

The iOS Twitter Kit does not have a project on Github so the only thing you can do for now is to post here - the team will be aware already.


#17

Great, so is the conversation here enough or should I start a new thread that says FEATURE REQUEST in the title or something else to ensure they understand what the community wants?


#18

This is fine. Thank you.