Media type unrecognized with mp4 video

video
api

#1

Hi. First time in the forum.

I’m trying to upload a mp4 video with the Abraham-TwitterOAuth library and I’m always getting the { ["request"]=> string(22) "/1.1/media/upload.json" ["error"]=> string(24) "media type unrecognized." }. I already upload an image without problem. The video is the one that Abraham posted in his github (video-link)

My code, just in case

$connection = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret);
$content = $connection->get("account/verify_credentials");

$status = “Uploading a video with Twitter API”;

$media1 = $connection->upload(‘media/upload’, array(‘media’ => DIR.’/…/videos/video.mp4’, ‘media_type’ => ‘video/mp4’), true);

$connection->post(‘statuses/update’, array(
‘status’ => $status,
‘media_ids’ => implode(’,’, array($media1->media_id_string))
));

Thanks in advance.


#2

I figure it out the solution and modify the uploadMediaChunked function of the library.

 private function uploadMediaChunked($path, $parameters)
    {
        // Init
        $file = file_get_contents($parameters['media']);
        $data = base64_encode($file);
        $init = $this->http('POST', self::UPLOAD_HOST, $path, [
            'command' => 'INIT',
            'media_data' => $data,
            'media_type' => $parameters['media_type'],
            'total_bytes' => filesize($parameters['media'])
        ]);
        // Append
        $segment_index = 0;
        $media = fopen($parameters['media'], 'rb');
        while (!feof($media))
        {
            $this->http('POST', self::UPLOAD_HOST, 'media/upload', [
                'command' => 'APPEND',
                'media_id' => $init->media_id,
                'segment_index' => $segment_index++,
                'media_data' => base64_encode(fread($media, self::UPLOAD_CHUNK))
            ]);
        }
        fclose($media);
        // Finalize
        $finalize = $this->http('POST', self::UPLOAD_HOST, 'media/upload', [
            'command' => 'FINALIZE',
            'media_id' => $init->media_id_string
        ]);
        return $finalize;
    }