Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upMedia upload not working as it seems it should in test case. #646
Comments
This comment has been minimized.
This comment has been minimized.
barkermn01
commented
Apr 18, 2018
•
|
Complete overhaul of this post as I have even more debugging: and some major evidence that some stuff is going wrong a twitter: but I think I have now found out it also ties in the issue: #625 private function uploadMediaChunked($path, array $parameters)
{
$initParams = $this->mediaInitParameters($parameters);
$init = $this->http('POST', self::UPLOAD_HOST, $path, $initParams);
// Append
$segmentIndex = 0;
$media = fopen($parameters['media'], 'rb');
$totalSegmants = ceil($initParams['total_bytes']/$this->chunkSize);
$totalSent = 0;
while (!feof($media))
{
$bin = fread($media, $this->chunkSize);
error_log("segment ".($segmentIndex+1)."/{$totalSegmants} is of size ".strlen($bin)." bytes ");
$this->http('POST', self::UPLOAD_HOST, 'media/upload', [
'command' => 'APPEND',
'media_id' => $init->media_id_string,
'segment_index' => $segmentIndex++,
'media' => $bin
]);
$totalSent += strlen($bin);
error_log("sent {$totalSent}/{$initParams['total_bytes']}");
}
fclose($media);
// Finalize
$finalize = $this->http('POST', self::UPLOAD_HOST, 'media/upload', [
'command' => 'FINALIZE',
'media_id' => $init->media_id_string
]);
//check media is ready
while(true){
error_log("sending STATUS requet for {$init->media_id_string}");
$data = $this->http('POST', self::UPLOAD_HOST, 'media/upload', [
'command' => 'STATUS',
'media_id' => $init->media_id_string,
]);
error_log("state = ".json_encode($data));
if($data->processing_info->state != 'in_progress'){
if($data->processing_info->state == "failed"){
error_log("failed to upload media to twitter {$data->processing_info->error->message}");
throw new \Exception("Upload media to twitter failed \r\n {$data->processing_info->error->message}");
}
break;
}
if(isset($data->processing_info)){
sleep($data->processing_info->check_after_secs);
}
}
return $finalize;
}As you can see there is a whole load of debugging added in I have also changed it to use binary So far all I'm seem to be getting is more code evidence that this is a Twitter API error while I have the forum post open from them I will leave this open but if it turns out I don't need to fix anything in this code base from them I will close this ticket, if I do I will push a fix once it is confirmed what is going wrong. But the latest evidence shows a couple of problems with twitters API the first is telling me an attribute is required when it is not according to the documentation (from below and the And the output provided:
|
barkermn01 commentedApr 18, 2018
•
edited
So I have double checked this against the test case and for some reason, it does not work for me.
But for some reason, this fails every time I try it, and I have tested the video I am testing with using https://github.com/twitterdev/large-video-upload-python and it works I did ask for help on twitter forums before confirming it is a problem with this library.
https://twittercommunity.com/t/media-upload-rejecting-mp4-videos/104181
Oh and just a note on that note when uploading an image when I'm calling and it works perfectly...