使用YouTube Python API禁用评论/评级?

2024-09-29 21:57:48 发布

您现在位置:Python中文网/ 问答频道 /正文

有人知道是否可以使用pythonapi禁用YouTube的评分/评论?我知道您可以在XML请求中使用'yt:accessControl'标记来完成,但是我不知道如何手动构建请求。如有任何帮助,我们将不胜感激:)


Tags: 标记pythonapiyoutube评论xml手动评分yt
2条回答

您可以使用扩展元素,请检查here和上一个答案here

评分、评论、列表都是yt:accessControl的一部分

我相信您需要使用YouTube API的2.0版本,各种特定语言的API,包括Python,目前只提供1.0版本。但是,更新一个视频以使用裸机2.0操作来更改访问控制并不难,即使您正在通过特定于语言的API执行其他所有操作。The docs(对于2.0 API)解释:

To update a video, send an HTTP PUT request to the URL identified in the video entry's <link> tag where the rel attribute value is edit:

<link rel='edit' type='application/atom+xml'
   href='http://gdata.youtube.com/feeds/api/users/USER_ID/uploads/VIDEO_ID'>

The body of the PUT request is an Atom XML entry that contains information about the video. You can include any of the following elements and their subtags in your request. Required elements are marked with an asterisk (*).

^{pr2}$

Note that excluding an element will delete the information that already exists for that video.

…因此,您必须重复上载时提供的一些信息(以避免删除该信息),以便能够添加yt:accessControl元素。在

上传的文档有一个complete example标题、multipart-related格式和您将要发送的XML(根据文档的this part添加访问控制标记),但示例是POST,而不是PUT,因为它上载的是视频,而不是更改其信息(和访问控制)。要通过Python的标准库发送GET和POST以外的HTTP方法,请使用httplib:生成一个HTTPConnection,然后调用其request方法,其中PUT作为第一个参数,然后是URL(主机之后的部分,请参阅Python联机文档本节末尾的示例),正文(Youtube 2.0API文档中的示例部分

 f93dcbA3
Content-Type: application/atom+xml; charset=UTF-8

<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"

最后是标题)。在

是的,它绝对没有gdataapi那么方便,但是,在gdataapi更新为支持2.0api功能之前,我怀疑这是最好的方法。主要的替代方法是调整PythonAPI源代码(找到here),以添加您需要的2.0位功能,但是,我觉得这项工作要做得更多。在

相关问题 更多 >

    热门问题