I managed to upload videos by this example code
$videoPath = "/path/to/file.mp4";
// Create a snippet with title, description, tags and category ID
// Create an asset resource and set its snippet metadata and type.
// This example sets the video's title, description, keyword tags, and
// video category.
$snippet = new Google_Service_YouTube_VideoSnippet();
$snippet->setTitle("Test title");
$snippet->setDescription("Test description");
$snippet->setTags(array("tag1", "tag2"));
// Numeric video category. See
// https://developers.google.com/youtube/v3/docs/videoCategories/list
$snippet->setCategoryId("22");
// Set the video's status to "public". Valid statuses are "public",
// "private" and "unlisted".
$status = new Google_Service_YouTube_VideoStatus();
$status->privacyStatus = "public";
// Associate the snippet and status objects with a new video resource.
$video = new Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
// Specify the size of each chunk of data, in bytes. Set a higher value for
// reliable connection as fewer chunks lead to faster uploads. Set a lower
// value for better recovery on less reliable connections.
$chunkSizeBytes = 1 * 1024 * 1024;
// Setting the defer flag to true tells the client to return a request which can be called
// with ->execute(); instead of making the API call immediately.
$client->setDefer(true);
// Create a request for the API's videos.insert method to create and upload the video.
$insertRequest = $youtube->videos->insert("status,snippet", $video);
// Create a MediaFileUpload object for resumable uploads.
$media = new Google_Http_MediaFileUpload(
$client,
$insertRequest,
'video/*',
null,
true,
$chunkSizeBytes
);
$media->setFileSize(filesize($videoPath));
// Read the media file and upload it chunk by chunk.
$status = false;
$handle = fopen($videoPath, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
fclose($handle);
// If you want to make other calls after the file upload, set setDefer back to false
$client->setDefer(false);
from https://developers.google.com/youtube/v3/code_samples/php#resumable_uploads
After the files uploaded I'm getting [Raw file: unknown]
in column "Video Information
"
The same happens with uploading files from Google Drive to YouTube by "Import your videos from Google+
" on this page https://www.youtube.com/upload
.
When I click button "Edit
" on uploaded video we go to this url https://www.youtube.com/edit?o=U&video_id=XXX
and in column "Video Information
" there is "Raw file: unknown
".
All uploaded video files does have normal titles and they are video/mp4
mime type.
I didn't find anything on Google Drive API about how to change it. Instead of "unknown
" can it have the same name as the file?
If you would like to include the filename in you API uploads you must add the fileDetails parts to your API upload request and include the fileDetails object in the body of your request as well as the fileName parameter set to the name of the file you desire.
This is documented here: https://developers.google.com/youtube/v3/docs/videos#fileDetails.fileName