I upload videos to YouTube programmatically using the YouTube API. Some of my videos should be flagged as age-limited, so I want to specify the AgeGating video attribute. When video.setAgeGating (gating) is specified, the corresponding part name should be provided, otherwise I get the following error:
{
"code" : 400,
"errors" : [ {
"domain" : "youtube.part",
"location" : "part",
"locationType" : "parameter",
"message" : "ageGating",
"reason" : "unexpectedPart"
} ],
"message" : "ageGating"
}
The documentation contains the following available parts:
fragment, contentDetails, fileDetails, liveStreamingDetails, player, processingDetails, recordDetails, statistics, status, offers, and topicDetails.
None of them work in my case, still returning the same message unexpected Part , so I tried the user name ageGating , although this time the answer:
{
"code" : 403,
"errors" : [ {
"domain" : "youtube.common",
"message" : "Forbidden",
"reason" : "forbidden"
} ],
"message" : "Forbidden"
}
API YouTube.
:
Video videoMetadata = new Video();
VideoStatus status = new VideoStatus();
status.setPrivacyStatus("public");
videoMetadata.setStatus(status);
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);
InputStreamContent videoContent = new InputStreamContent(
VIDEO_FILE_FORMAT, new BufferedInputStream(new FileInputStream(videoFile)));
videoContent.setLength(videoFile.length());
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();
- ?