How to disable comments and ratings using the asp.net YouTube API

Any help would be greatly 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
source share
3 answers

The method below uses the YouTube video obtained from the YouTube request service, as well as the permission type and 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 the extracted video, not if you transfer the "new video ()"

what it does is iterates over all the ExtentionElements that you use as part of the feed and retrieves the xml extension elements (since there is no extension in C # access control extension) takes elements that match the == type action then updates permission attribute to the desired value.

- YouTube, .

+1

API Youtube, <yt:accessControl>, .

.

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

API Youtube

+1

update video status youtube 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);
0
source

Source: https://habr.com/ru/post/1790674/


All Articles