Upload videos via YouTube API

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();

// 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();

- ?

+4
2

, , youtube Age Restricted

, API YouTube. , POST a

:

snippet.title
snippet.description
snippet.tags[]
snippet.categoryId
status.privacyStatus
status.embeddable
status.license
status.publicStatsViewable
status.publishAt
recordingDetails.locationDescription
recordingDetails.location.latitude
recordingDetails.location.longitude
recordingDetails.recordingDate

: contentDetails.contentRating.ytRating = "ytAgeRestricted" , , POST POST API Youtube

    {
      ... 
      "contentDetails": {
        ...
        "contentRating": {
                "ytRating": "ytAgeRestricted"
            }
            ...
        }
    }
0

All Articles