The below method takes in a YouTube video retrieved from the YouTube request service and also takes in the type of permission and the new permissions.
private Video SetAccessControl(Video video, string type, string permission)
{
var exts = video.YouTubeEntry
.ExtensionElements
.Where(x => x is XmlExtension)
.Select(x => x as XmlExtension)
.Where(x => x.Node.Attributes["action"] != null && x.Node.Attributes["action"].InnerText == type);
var ext = exts.FirstOrDefault();
if (ext != null)
ext.Node.Attributes["permission"].InnerText = permission;
return video;
}
NOTE this will only work on a retrieved video, not if you pass in a "new Video()"
what it does is, iterates over all the ExtentionElements that you tube returned as part of the feed, and extracts the xml extension elements (as there isn't a build in c# access control extension) takes the elements that match where the action == type then updates the permissions attribute to the required value.
When the video entry is sent and updated to the YouTube server the updated access control elements are sent back and with the update request.