1

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

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I also had to add a null check on the Attributes list. So the last where statement looks like this: .Where(x => x.Node.Attributes != null && x.Node.Attributes["action"] != null && x.Node.Attributes["action"].InnerText == type);
1

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

2 Comments

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?
You specifiy it in the HTTP Request, there is an example of doing it on the up date here: code.google.com/apis/youtube/2.0/… so I assume it would be similar on the create too.
0

update youtube video status fron UNLISTED to Public

        YouTubeRequestSettings settings = new YouTubeRequestSettings(_application, _developerkey, _username, _password);
        Uri videoEntryUrl = new Uri("https://gdata.youtube.com/feeds/api/users/default/uploads/" + VideoID); 
        YouTubeRequest Request = new YouTubeRequest(settings); 
        Video Video = Request.Retrieve<Video>(videoEntryUrl);
        List<Google.GData.YouTube.YtAccessControl> AccessControlsArray = Video.YouTubeEntry.AccessControls.ToList();
        foreach (var item in AccessControlsArray)
        {        
            if (item.Attributes["action"].ToString()=="list") 
            { 
                item.Attributes["permission"]= "allowed"; 
            } 
        }

        Video = Request.Update(Video);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.