gpt4 book ai didi

java - 如何正确应用 yt :accessControl in YouTube-API Java

转载 作者:行者123 更新时间:2023-12-02 07:55:34 26 4
gpt4 key购买 nike

我在 YouTube 上上传了一个视频,我希望更改 yt:accessControls(尤其是评论审核)。我查看了 YouTube API 引用 herehere ,但我似乎无法正确更新它。这是我的代码:

//Strings declared beforehand: appName, developerId, username, password, and vidId.
YouTubeService service = new YouTubeService(appName, developerId);
service.setUserCredentials(username, password);

String videoEntryUrl = "http://gdata.youtube.com/feeds/api/users/default/uploads/" + vidId;
VideoEntry createdEntry = service.getEntry(new URL(videoEntryUrl), VideoEntry.class);

String originalXMLBlob = createdEntry.getXmlBlob().getBlob();

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

String newXMLBlob = createdEntry.getXmlBlob().getBlob().substring(49);
//The substring(49) is because after you do a service.parseResponseData... it attaches a timestamp to the xmlBlob. To properly compare whether these are the same in the printlns I substring it.

System.out.println(newXMLBlob.equals(originalXMLBlob));
System.out.println(originalXMLBlob);
System.out.println(newXMLBlob);
createdEntry.update();
createdEntry.update();

newXMLBlob = createdEntry.getXmlBlob().getBlob().substring(49);
System.out.println(newXMLBlob.equals(originalXMLBlob));
System.out.println(originalXMLBlob);
System.out.println(newXMLBlob);
System.out.println("Done");

输出为:

false
<yt:accessControl permission='allowed' action='comment'/><yt:accessControl permission='allowed' action='commentVote'/><yt:accessControl permission='moderated' action='videoRespond'/><yt:accessControl permission='allowed' action='rate'/><yt:accessControl permission='allowed' action='embed'/><yt:accessControl permission='allowed' action='list'/><yt:accessControl permission='allowed' action='autoPlay'/><yt:accessControl permission='allowed' action='syndicate'/>
<yt:accessControl permission='moderated' action='comment'/><yt:accessControl permission='allowed' action='commentVote'/><yt:accessControl permission='moderated' action='videoRespond'/><yt:accessControl permission='allowed' action='rate'/><yt:accessControl permission='allowed' action='embed'/><yt:accessControl permission='allowed' action='list'/><yt:accessControl permission='allowed' action='autoPlay'/><yt:accessControl permission='allowed' action='syndicate'/>
false
<yt:accessControl permission='allowed' action='comment'/><yt:accessControl permission='allowed' action='commentVote'/><yt:accessControl permission='moderated' action='videoRespond'/><yt:accessControl permission='allowed' action='rate'/><yt:accessControl permission='allowed' action='embed'/><yt:accessControl permission='allowed' action='list'/><yt:accessControl permission='allowed' action='autoPlay'/><yt:accessControl permission='allowed' action='syndicate'/>
<yt:accessControl permission='moderated' action='comment'/><yt:accessControl permission='allowed' action='commentVote'/><yt:accessControl permission='moderated' action='videoRespond'/><yt:accessControl permission='allowed' action='rate'/><yt:accessControl permission='allowed' action='embed'/><yt:accessControl permission='allowed' action='list'/><yt:accessControl permission='allowed' action='autoPlay'/><yt:accessControl permission='allowed' action='syndicate'/>
Done

重要的是从开始到结束没有任何改变。您可以看到我什至尝试执行 createdEntry.update(); 但这也不起作用。任何帮助将不胜感激!谢谢!

哦,还有最后一件事。我希望我的atomXml 能够设置对多个事物(视频响应、评级等)的访问控制。我猜您只是添加更多 yt:accessControl 标签,但在回答时,如果您对此有任何提示,我将不胜感激。再次感谢。

编辑:删除了 xml 中 url 中的空格。这导致输出发生变化(也更新),这更有意义,但这不是所需的解决方案。

最佳答案

如果我最初没有在 xml 中提出空间问题,我就不必发布这个问题。事实证明,您无法在上传视频后立即更新 yt:accessControl。因此,我会保存 Id,然后上传它们,然后当它们全部完成时,我将更新每个 Id 上的 yt:accessControl。希望这对后来者有所帮助。

哦,顺便说一句,我很确定您可以一次提交多个 yt:accessControls。快乐编码!

关于java - 如何正确应用 yt :accessControl in YouTube-API Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9703858/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com