1

I'm trying to share a video to Twitter Account but getting a response like below

stdClass Object ( [request] => /1.1/media/upload.json [error] => Segments do not add up to provided total file size. [httpstatus] => 400 [rate] => stdClass Object ( [limit] => 615 [remaining] => 613 [reset] => 1576651447 ) )

I don't know what to do to fix this issue. If anyone experienced this please let me know.

This is my code to share video to twitter.

\Codebird\Codebird::setConsumerKey(CONSUMER_KEY, CONSUMER_SECRET);        
$cb = \Codebird\Codebird::getInstance();        
$cb->setToken($access_token, $access_token_secret);        
$file       = $videopath;       
$size_bytes = filesize($file);       
$fp         = fopen($file, 'r');

// INIT
$reply = $cb->media_upload([
'command'     => 'INIT',
'media_type'  => 'video/mp4',
'total_bytes' => $size_bytes
]);

$media_id = $reply->media_id_string;

// APPEND

$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
    ]);

    $segment_id++;
}

fclose($fp);

// FINALIZE

$reply = $cb->media_upload([
    'command'       => 'FINALIZE',
    'media_id'      => $media_id
]);

if ($reply->httpstatus < 200 || $reply->httpstatus > 299) { 
    die();
}

// Now use the media_id in a Tweet
$reply = $cb->statuses_update([
'status'    => $msg,
'media_ids' => $media_id
]);

I'm getting an error in the Finalize command result.

I tried to fix this but I can't because I don't know the exact reason for this issue and I didn't know how to handle and fix this. Can anyone help me to fix this? The above is the code I have used to share the post to the twitter account. And one thing is, the above code works fine when I tried to share the post immediately to twitter using this API but the issue is only when I tried to share the post by scheduling it with a specific time to share.

And when I trying to share a video below 1mb it gets shared. When I tried a video with 1mb or more than that I got the below error while sharing to account.

{"errors":[{"code":324,"message":"Invalid media id 1215261697298108416"}],"httpstatus":400,"rate":null}

Ramya.K
  • 19
  • 5
  • Can you share the code that results in this error? It sounds as though there maybe a miscalculation in the way you are chunking up your video for upload. – Andy Piper Dec 18 '19 at 13:09
  • Have shared my code above. please check and let me know if i have made something wrong. – Ramya.K Dec 20 '19 at 06:14
  • Now i'm not getting the above mentioned "Segment" error instead of that i'm getting this error "stdClass Object ( [httpstatus] => 204 [rate] => stdClass Object ( [limit] => 20000 [remaining] => 19424 [reset] => 1578581536 ) )". Can anyone let us know about the limit and remaining value calculation mentioned in the error status. – Ramya.K Jan 09 '20 at 14:11
  • HTTP 204 translates to No Content. The limit and remaining headers relate to the rate limit for the media upload endpoint. I assume the Codebird library is masking any other messages or headers. – Andy Piper Jan 09 '20 at 16:26
  • I have explained my issue in this question above. Please check below the code so that you will get the clear picture that what I have experienced now. – Ramya.K Jan 11 '20 at 05:59

0 Answers0