通过Java中的youtube API禁用视频评论

时间:2012-01-20 00:13:22

标签: youtube youtube-api

如何在使用Youtube API上传视频时禁用评论,在java?

1 个答案:

答案 0 :(得分:3)

快速推出Google之后,我找到了this

您要做的是将yt:accessControl元素添加到视频条目,其中action属性为“comment”,权限属性为“moderated”。我不相信Java客户端库中存在本机支持或yt:accessControl元素,因此必须“手动”完成。这是一些示例代码 假设您刚刚创建了一个新视频,然后执行部分更新以设置该视频的yt:accessControl值:

VideoEntry createdEntry = service.insert(new URL(uploadUrl), newEntry);

String atomXml = "<?xml version='1.0'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' gd:fields='yt:accessControl' xmlns:yt='http://gdata.youtube.com/schemas/2007'><yt:accessControl action='comment' permission='moderated'/></entry>";

GDataRequest request = service.createPatchRequest(new URL(createdEntry.getEditLink().getHref()));
request.getRequestStream().write(atomXml.getBytes("UTF-8"));
request.execute();
createdEntry = service.parseResponseData(request, VideoEntry.class);

// createdEntry now contains the updated VideoEntry, and the access control should be set on it.