I'm uploading video to YouTube programmatically using YouTube API. Some of my videos need to be labeled age-restricted, so I want to specify AgeGating video attribute. When video.setAgeGating(gating) is specified the appropriate part name has to be provided as well, other way I get the following error
{
"code" : 400,
"errors" : [ {
"domain" : "youtube.part",
"location" : "part",
"locationType" : "parameter",
"message" : "ageGating",
"reason" : "unexpectedPart"
} ],
"message" : "ageGating"
}
The documentation states the following available parts:
snippet, contentDetails, fileDetails, liveStreamingDetails, player, processingDetails, recordingDetails, statistics, status, suggestions, and topicDetails.
None of them works in my case still returning the same unexpectedPart error message, so I've tried a custom ageGating part name, though this time the response is:
{
"code" : 403,
"errors" : [ {
"domain" : "youtube.common",
"message" : "Forbidden",
"reason" : "forbidden"
} ],
"message" : "Forbidden"
}
This error type is not listed in the YouTube API errors documentation page.
Here's my code sample:
Video videoMetadata = new Video();
// set status
VideoStatus status = new VideoStatus();
status.setPrivacyStatus("public");
videoMetadata.setStatus(status);
// set metadata snippet
VideoSnippet snippet = new VideoSnippet();
snippet.setTitle("Test Upload");
snippet.setDescription("YouTube Data API V3");
List<String> tags = new ArrayList<String>();
tags.add("YouTube Data API V3");
tags.add("Test Upload");
snippet.setTags(tags);
videoMetadata.setSnippet(snippet);
// set video content
InputStreamContent videoContent = new InputStreamContent(
VIDEO_FILE_FORMAT, new BufferedInputStream(new FileInputStream(videoFile)));
videoContent.setLength(videoFile.length());
// set age gating
VideoAgeGating gating = new VideoAgeGating();
gating.setRestricted(true);
videoMetadata.setAgeGating(gating);
YouTube.Videos.Insert videoInsert = youtube.videos()
.insert("ageGating,snippet,statistics,status", videoMetadata, videoContent);
Video returnedVideo = videoInsert.execute();
Is it forbidden to specify age restriction for new videos, or is there another video-part name for this case?