Hi, does anyone know if it's possible to disable YouTube ratings/comments using the Python API? I know you can do it using the 'yt:accessControl' tag in the XML request but I have no idea how to build a request manually. Any help would be appreciated :)
I believe you need to use the 2.0 version of the YouTube API, and the various language-specific APIs, including Python, only provide 1.0 versions at this time. But it's not hard to update a video to change access control with a bare-metal 2.0 operation, even if everything else you're doing through a language-specific API. The docs (for the 2.0 API) explain:
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 (*).
media:title*
media:description*
media:category*
media:keywords*
yt:accessControl
yt:location
yt:private
georss:where
Note that excluding an element will delete the information that already exists for that video.
...so you'll have to repeat some of the info you already gave on uploading (to avoid deleting that information) in order to be able to add yt:accessControl
elements.
The docs for uploading have a complete example of the headers, multipart-related
formatting, and XML you would be sending (with the addition of the access control tags as per this part of the docs) -- but the example is a POST
, not a PUT
, because it's uploading a video, not changing its info (and access control). To send HTTP methods other than GET and POST via Python's standard library, use httplib: make an HTTPConnection
and then call its request method with PUT
as the first argument, then URL (the part after the host, see the examples at the end of this section of the Python online docs), body (the part that in the example in the docs for the Youtube 2.0 API starts
--f93dcbA3
Content-Type: application/atom+xml; charset=UTF-8
<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
and finally the headers).
Yes, it's definitely not quite as handy as the GData API, but, until the latter is updated to support the 2.0 API functionality, I do suspect it's the best way. The main alternative would be to tweak the Python API sources (found here) to add the 2.0 bit of functionality you require, but, offhand, that seems to me to be even more work.