I'm using the latest version of Codebird to tweet from my site. I'm trying to add the ability to tweet videos, the code successfully tweets images.
I can't find anything additional on the web. Here is the code:
\Codebird\Codebird::setConsumerKey(xxxx, xxxx);
$cb = \Codebird\Codebird::getInstance();
$cb->setToken(xxxx, xxxx);
$video = /path/to/file.mp4
$params = [
'status' => mb_substr('the tweet text', 0, 280),
'media_ids' => twitterUpdloadLargeFile($cb, $video)
];
$reply = $cb->statuses_update($params); // code 324 'not valid video'
function twitterUpdloadLargeFile($cb, $video) {
$size_bytes = filesize($video); // test video 2.5MB
$mime = mime_content_type($video);
$fp = fopen($video, 'r');
$reply = $cb->media_upload([
'command' => 'INIT',
'media_type' => $mime,
'media_category' => 'tweet_video',
'check_progress' => true,
'total_bytes' => $size_bytes,
]);
$media_id = $reply->media_id_string;
$segment_id = 0;
while (! feof($fp)) {
$chunk = fread($fp, 524288); // 512KB per chunk
$reply = $cb->media_upload([
'command' => 'APPEND',
'media_id' => $media_id,
'segment_index' => $segment_id,
'media' => $chunk
]);
$segment_id++;
}
fclose($fp);
$reply = $cb->media_upload([
'command' => 'FINALIZE',
'media_id' => $media_id,
'media_category' => 'tweet_video',
]);
return $reply->media_id_string;
}
The above code results in code 324 and the message "Not valid video", and nothing shows up on Twitter.
The INIT upload gives status 202. Each APPEND gives status 204. The 'FINALIZE' upload gives status 200.