5

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?

mzhuk
  • 140
  • 10

2 Answers2

0

contentDetails should do the trick, here's the resource under contentDetails. https://developers.google.com/youtube/v3/docs/videos#contentDetails.contentRating.ytRating

Ibrahim Ulukaya
  • 12,767
  • 1
  • 33
  • 36
  • 1
    Hi Ibrahim, I was wondering if you could help me with a similar issue regarding title of the upload request. I use snippet.title and that does not seem to work. – Rjdlee Oct 26 '14 at 19:32
0

Reading the documentation it seems that youtube Age Restricted property is another Content Rating

If i understand the documentation, you can't set this property via YouTube API. I read that you must POST a video Resource in the request body and you can only set some of the properties of the video resource

You can set values for these properties:

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

You can read this property as: contentDetails.contentRating.ytRating = "ytAgeRestricted" but it looks like you can't POST this property in the video Resource in the body of your POST request to Youtube API

    {
      ... 
      "contentDetails": {
        ...
        "contentRating": {
                "ytRating": "ytAgeRestricted"
            }
            ...
        }
    }
Gonza
  • 360
  • 2
  • 12
  • Looks like that's what it is. This property is read-only. Not very developer-friendly, at least they should have described such behavior in their documentation (or provided an according error code). Any luck with updating an existing video? – mzhuk Sep 30 '14 at 20:27