Have fun, I use Google api v3 to upload videos to YouTube. Unfortunately I'm facing this error since yesterday without any changes in the code or server.
I searched for the error text in different sections but didn't get any results. The only thing I found was this package and the file at this address src/Http/MediaFileUpload.php Specify content-type, the value is application/json; set charset=UTF-8. I think that's the problem. Please guide me.
Thanks
"error": { "code": 400, "message": "Media type 'application/json; charset=UTF-8' is not supported. ", "errors": [ { "message": "Media type 'application/json; charset=UTF-8' is not supported. ", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" }
$chunkSizeBytes = 15 * 1024 * 1024; $client->setDefer(true); $insertRequest = $youtube->videos->insert("status,snippet,recordingDetails", $video , [ 'notifySubscribers' => true ]); $media = new MediaFileUpload( $client, $insertRequest, 'video/'.File::extension($videoPath), null, false, $chunkSizeBytes ); $media->setFileSize(File::size($videoPath)); $status = false; $handle = fopen($videoPath, "rb"); while (!$status && !feof($handle)) { $chunk = fread($handle, $chunkSizeBytes); $status = $media->nextChunk($chunk); } fclose($handle); $client->setDefer(false);
Looking at the code, the media type
application/json
occurs when$resumable
is false (see here and here).So I would try setting
$resumable = true
(which is the fifth parameter ofMediaFileUpload
). You can find it atlarge-file-upload.php
.