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

发布于 2024-12-27 23:32:51 字数 38 浏览 0 评论 0原文

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

How to disable comments when uploading a video with Youtube API, in java ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七秒鱼° 2025-01-03 23:32:51

经过快速谷歌后,我发现这个< /a>.

您想要做的是将 yt:accessControl 元素添加到视频条目,其操作属性为“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.

After a quick Google, I found this.

What you want to do is add an yt:accessControl element to the video entry, with an action attribute of "comment" and a permission attribute of "moderated". I don't believe that there is native support or the yt:accessControl element in the Java client library yet, so this would have to be done "by hand". Here's some example code that
assumes you've just created a new video, and then performs a partial update to set the yt:accessControl value for that video:

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文