The CodeBird example you linked to does work successfully, but it looks like your code is using a combination of the Codebird example with TwitterOAuth. I believe your issues may lie somewhere in here.
From what I can tell, TwitterOAuth manages the media upload chunked process through a boolean param called “chunked” in the upload function. As found here.
This allows for the TwitterOAuth library to use only one method call and eliminate the need for a separate INIT, APPEND, and FINALIZE call.
//Example of successful media chunked upload
$media = $connection->upload('media/upload',
[
'media_type' => 'video/mp4',
'media_category' => 'tweet_video',
'total_bytes' => $size,
'media' => '[FILE_URL]',
],true);
However, you will need to check for the STATUS of the file to ensure the file has completed uploading before being tweeted. If the media is still processing, the tweet will post without an attached video.
//Example of Media Status call
$media = $connection->mediaStatus($mediaId);
//Example of Media Status call using the check_after_secs field
if(isset($media->processing_info)) {
$info = $media->processing_info;
print_r($info->state);
if($info->state != 'succeeded') {
$attempts = 0;
$checkAfterSecs = $info->check_after_secs;
$success = false;
do {
$attempts++;
sleep($checkAfterSecs);
$media = $connection->mediaStatus($mediaId);
$procInfo = $media->processing_info;
if($procInfo->state == 'succeeded' || $procInfo->state == 'failed') {
break;
}
$checkAfterSecs = $procInfo->check_after_secs;
} while($attempts <= 10);
}
}
Once the STATUS shows that the upload has succeeded, you can post a tweet with the media attached.
$result = $connection->post('statuses/update',
[
'media_ids'=> $mediaId,
'status'=> 'This is the text of your tweet!'
]);
Hopefully this info helps!