My Code(PHP) for uploading video on Twitter:
$reply = $cb->media_upload([
‘command’ => ‘INIT’,
‘media_type’ => ‘video/mp4’,
‘total_bytes’ => $mediaSize,
]);
print_r($reply);
$media_id = $reply->media_id_string;
// APPEND data to the upload
$segment_id = 0;
while (!feof($fp)) {
$chunk = fread($fp, 1048576); // 1MB per chunk for this sample
$reply = $cb->media_upload([
‘command’ => ‘APPEND’,
‘media_id’ => $media_id,
‘segment_index’ => $segment_id,
‘media’ => $chunk,
‘media_category’ => “TWEET_VIDEO”,
]);
print_r([$reply, $segment_id]);
$segment_id++;
}
fclose($fp);
// FINALIZE the upload
$reply = $cb->media_upload([
‘command’ => ‘FINALIZE’,
‘media_id’ => $media_id,
‘media_category’ => “TWEET_VIDEO”,
]);
print_r($reply);
// Now use the media_id in a Tweet
$reply = $cb->statuses_update([
‘status’ => $postDescription,
‘media_ids’ => $media_id,
]);
Output:
-------- INIT ---------
(
[media_id] => 1104959576267358209
[media_id_string] => 1104959576267358209
[expires_after_secs] => 86400
[httpstatus] => 202
[rate] => stdClass Object
(
[limit] => 200
[remaining] => 196
[reset] => 1552280658
)
)
-------- APPEND ---------
stdClass Object
(
[httpstatus] => 204
[rate] => stdClass Object
(
[limit] => 20000
[remaining] => 19967
[reset] => 1552280664
)
)
stdClass Object
(
[httpstatus] => 204
[rate] => stdClass Object
(
[limit] => 20000
[remaining] => 19966
[reset] => 1552280664
)
)
stdClass Object
(
[httpstatus] => 204
[rate] => stdClass Object
(
[limit] => 20000
[remaining] => 19965
[reset] => 1552280664
)
)
stdClass Object
(
[httpstatus] => 204
[rate] => stdClass Object
(
[limit] => 20000
[remaining] => 19964
[reset] => 1552280664
)
)
stdClass Object
(
[httpstatus] => 204
[rate] => stdClass Object
(
[limit] => 20000
[remaining] => 19963
[reset] => 1552280664
)
)
stdClass Object
(
[httpstatus] => 204
[rate] => stdClass Object
(
[limit] => 20000
[remaining] => 19962
[reset] => 1552280664
)
)
stdClass Object
(
[httpstatus] => 204
[rate] => stdClass Object
(
[limit] => 20000
[remaining] => 19961
[reset] => 1552280664
)
)
stdClass Object
(
[httpstatus] => 204
[rate] => stdClass Object
(
[limit] => 20000
[remaining] => 19960
[reset] => 1552280664
)
)
----------- FINALIZE -----------
stdClass Object
(
[media_id] => 1104959576267358209
[media_id_string] => 1104959576267358209
[size] => 7687982
[expires_after_secs] => 86400
[video] => stdClass Object
(
[video_type] => video/mp4
)
[httpstatus] => 201
[rate] => stdClass Object
(
[limit] => 615
[remaining] => 610
[reset] => 1552280693
)
)
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[code] => 324
[message] => Duration too long, maximum:30000, actual:77276 (MediaId: snf:1104959576267358209)
)
)
[httpstatus] => 400
[rate] =>
)