【发布时间】: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