tags:

views:

87

answers:

2

Any help would be much appreciated!

Current code:

        YouTubeRequest request = Connect();
        Video video = new Video();

        video.Tags.Add(new MediaCategory("Nonprofit", YouTubeNameTable.CategorySchema));
        video.Keywords = "Test";
        video.YouTubeEntry.setYouTubeExtension("location", "UK");
+1  A: 

According to the Youtube API blog, you do it using the <yt:accessControl> tag, read here for more info.

e.g.

<yt:accessControl action='comment' permission='denied'/

Youtube API Blog Disable Comments Announcement

w69rdy
Yeah I found that post when doing a Google search but I can't see how to set those properties when creating the YouTube video object?
John Walker
You specifiy it in the HTTP Request, there is an example of doing it on the up date here: http://code.google.com/apis/youtube/2.0/developers_guide_protocol_updating_and_deleting_videos.html so I assume it would be similar on the create too.
w69rdy
Does anybody have any c# examples
John Walker
A: 

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.

tocs