【问题标题】:Uploading video via YouTube API通过 YouTube API 上传视频
【发布时间】:2014-09-27 20:22:23
【问题描述】:

我正在使用 YouTube API 以编程方式将视频上传到 YouTube。我的一些视频需要标记有年龄限制,所以我想指定 AgeGating 视频属性。 当指定 video.setAgeGating(gating) 时,还必须提供适当的部分名称,否则我会收到以下错误

{
  "code" : 400,
  "errors" : [ {
    "domain" : "youtube.part",
    "location" : "part",
    "locationType" : "parameter",
    "message" : "ageGating",
    "reason" : "unexpectedPart"
  } ],
  "message" : "ageGating"
}

documentation 声明了以下可用部分:

sn-p, contentDetails, fileDetails, liveStreamingDetails, player, processingDetails,recordingDetails,统计,状态,建议, 和topicDetails。

在我的情况下,它们都不起作用,仍然返回相同的 unexpectedPart 错误消息,所以我尝试了自定义 ageGating 部件名称,尽管这次响应是:

{
  "code" : 403,
  "errors" : [ {
    "domain" : "youtube.common",
    "message" : "Forbidden",
    "reason" : "forbidden"
  } ],
  "message" : "Forbidden"
}

YouTube API errors documentation page 中未列出此错误类型。

这是我的代码示例:

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

是否禁止为新视频指定年龄限制,或者这种情况下是否有其他视频部分名称?

【问题讨论】:

  • 我也遇到了这个,运气好吗?
  • 您知道如何使用 API 为视频添加年龄限制

标签: api video youtube youtube-api google-api-java-client


【解决方案1】:

阅读文档似乎 youtube Age Restricted 属性是另一个 Content Rating

如果我了解文档,则无法通过 YouTube API 设置此属性。我读到您必须在请求正文中POST a video Resource,并且您只能设置视频资源的some of the 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

您可以将此属性读作:contentDetails.contentRating.ytRating = "ytAgeRestricted",但您似乎无法在您对 Youtube API 的 POST 请求正文中的视频资源中发布此属性

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

【讨论】:

  • 看起来就是这样。此属性是只读的。对开发人员不太友好,至少他们应该在文档中描述了这种行为(或提供了相应的错误代码)。更新现有视频有什么好运气吗?
【解决方案2】:

contentDetails 应该可以解决问题,这是 contentDetails 下的资源。 https://developers.google.com/youtube/v3/docs/videos#contentDetails.contentRating.ytRating

【讨论】:

  • 您好 Ibrahim,我想知道您是否可以帮助我解决有关上传请求标题的类似问题。我使用 sn-p.title,但似乎不起作用。
猜你喜欢
  • 2012-08-19
  • 1970-01-01
  • 2018-08-09
  • 2018-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-20
相关资源
最近更新 更多