Reputation: 21
I've been getting a "Raw: Unknown" filename for the videos I've been uploading to YouTube using the API. Looking at the YouTube API Library, I've seen that there is a
Google_Service_YouTube_VideoFileDetails()
method where you can set the filename, but when I try it I get the following error:
Caught Google service Exception 400 message is {
error": {
"errors": [
{
"domain": "youtube.part",
"reason": "unexpectedPart",
"message": "{0}",
"locationType": "parameter",
"location": "part"
}
],
"code": 400,
"message": "{0}"
}
}
Here is my code:
$snippet = new Google_Service_YouTube_VideoSnippet();
$snippet->setTitle("Test title");
$snippet->setDescription("Test description");
$snippet->setTags(array("tag1","tag2"));
$snippet->setCategoryId("27");
$status = new Google_Service_YouTube_VideoStatus();
$status->setPrivacyStatus('private');
$status->setPublishAt("2019-08-13T13:13:13.1Z");
$status->setEmbeddable(false);
$fileDetails = new Google_Service_YouTube_VideoFileDetails();
$fileDetails->setFileName("WI_YOUTUBE_COMMA_DESCRIPTION.mp4");
$video = new Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
$video->setFileDetails($fileDetails);
$chunkSizeBytes = 1 * 1024 * 1024;
$client->setDefer(true);
$insertRequest = $youtube->videos->insert("status,snippet,fileDetails", $video,
array('onBehalfOfContentOwner' => $contentOwnerId,
'onBehalfOfContentOwnerChannel' => $channelId));
Upvotes: 2
Views: 413
Reputation: 491
For youtube python API, to set the file name put 'Slug' in request header like:
insert_request.headers["Slug"] = fileName
Upvotes: 0
Reputation: 11
I know this topic is old, but I want to save someone else time if they happen across this same thing.
First off, you can not submit 'fileDetails' in this request, that is why you are getting this error. noogui was correct that 'Slug' is the solution, and this is how you would do it modifying your code:
$snippet = new Google_Service_YouTube_VideoSnippet();
$snippet->setTitle("Test title");
$snippet->setDescription("Test description");
$snippet->setTags(array("tag1","tag2"));
$snippet->setCategoryId("27");
$status = new Google_Service_YouTube_VideoStatus();
$status->setPrivacyStatus('private');
$status->setPublishAt("2019-08-13T13:13:13.1Z");
$status->setEmbeddable(false);
$video = new Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
$chunkSizeBytes = 1 * 1024 * 1024;
$client->setDefer(true);
$insertRequest = $youtube->videos->insert("status,snippet", $video,
array('onBehalfOfContentOwner' => $contentOwnerId,
'onBehalfOfContentOwnerChannel' => $channelId));
$insertRequest = $insertRequest->withHeader("Slug", "WI_YOUTUBE_COMMA_DESCRIPTION.mp4");
This only works when setDefer is set to true, otherwise the request is sent the instant you call insert().
Also, withHeader() returns a new instance of the request.
Upvotes: 1