Placing LONG video (>30 seconds) into tweets


#1

Hi Colleagues!

I use Twitter REST API to make tweets with text and video programmatically.
I do it from Node.js using ‘twitter’ module, but it’s not principal. The final web requests to make it done are much more interesting for me.

Previously I made it such a way:

  1. uploaded the video to Twitter asynchronously using
    /media/upload method with {file_path: 'path_to_uploaded_file'} parameter and got media_id;
  2. created a tweet using /statuses/update method with parameters:
    {status: 'Tweet text', media_ids: ['received_media_id']}

It worked perfectly but now we need to make tweets with longer video (with maximum length not 30 but 140 seconds). So now I try to do following steps:

  1. upload video the same way as before but with parameters
    {file_path: 'path_to_uploaded_file', media_category: 'tweet_video'} (the last one is necessary to upload longer video as discussed here);

  2. use the received media_id as a parameter for /statuses/update the same way as above.
    The first step works well. But the second gives me the following message:

    sharing to twitter failed : { [Error: Not valid video]
    cause:
    { [Error: Not valid video]
    message: ‘Not valid video’,
    code: 324,
    allErrors: [ { code: 324, message: ‘Not valid video’ } ],
    twitterReply: { errors: [ { code: 324, message: ‘Not valid video’ } ] },
    statusCode: 400 },
    isOperational: true,
    code: 324,
    allErrors: [ { code: 324, message: ‘Not valid video’ } ],
    twitterReply: { errors: [ { code: 324, message: ‘Not valid video’ } ] },
    statusCode: 400 }

It’s interesting that even short videos (<30 sec) uploaded with media_category parameter can’t be posted standard way via /statuses/update and return the same error message.

What am I doing wrong? And is there a way to make tweet with long video programmatically?


#2

Just curious to know if you’re able to test the same video using our large video upload sample and see if you get the same results?


#3

Thank you for the quick answer and beautiful example (although I needed to study Python for a while :slight_smile:. Such a pity that I hadn’s seen this link before.

Now I see my mistake clearly: it was forgotten to check the state of uploaded video: after FINALIZE phase ends, it still needs to be processed, so we need to call in cycle something like this (JS code):

let res = yield req.twitter.postMediaChunkedAsync(params); // it does all phases one-by-one
let processingInfo = res.processing_info;
while (processingInfo.state==='pending') {
    yield Promise.delay(processingInfo.check_after_secs * 1000);
    let res = yield req.twitter.get('/media/upload', {
        command: 'STATUS',
        media_id: mediaId
    });
    processingInfo = res.data.processing_info;
}

You’ve saved my day!


#4

Excellent, glad to hear this resolved things for you.


#5