我正在使用YouTube API以编程方式将视频上传到YouTube。我的一些视频需要被标记为年龄限制,所以我想指定AgeGating视频属性。当指定video.setAgeGating(门控)时,还必须提供适当的部件名,其他方法是获得以下错误
{
"code" : 400,
"errors" : [ {
"domain" : "youtube.part",
"location" : "part",
"locationType" : "parameter",
"message" : "ageGating",
"reason" : "unexpectedPart"
} ],
"message" : "ageGating"
}
文档声明了以下可用部分:
代码片段、contentDetails、fileDetails、liveStreamingDetails、player、processingDetails、recordingDetails、统计、状态、建议和topicDetails。
在我的示例中,它们都不起作用,但仍然返回相同的unexpectedPart错误消息,因此我尝试了自定义ageGating部件名,不过这次的响应是:
{
"code" : 403,
"errors" : [ {
"domain" : "youtube.common",
"message" : "Forbidden",
"reason" : "forbidden"
} ],
"message" : "Forbidden"
}
此错误类型未在YouTube API错误文档页中列出。
下面是我的代码示例:
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();
是否禁止为新视频指定年龄限制,或者是否有另一个视频部分的名称?
发布于 2014-09-29 17:48:41
阅读这些文档,youtube年龄限制的属性似乎是另一个内容评级
如果我理解这些文档,您就不能通过YouTube API设置这个属性。我读到,您必须在请求体中帖子一个视频资源,并且只能设置视频资源的一些属性。
您可以为这些属性设置值:
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“,但看起来您不能在发布请求正文的视频资源中发布该属性
{
...
"contentDetails": {
...
"contentRating": {
"ytRating": "ytAgeRestricted"
}
...
}
}
发布于 2014-09-24 17:15:49
contentDetails应该能做到这一点,这是contentDetails下的资源。https://developers.google.com/youtube/v3/docs/videos#contentDetails.contentRating.ytRating
https://stackoverflow.com/questions/25134301
复制相似问题