如何禁止使用YouTube API asp.net评论和评级 [英] How do I disable comments and ratings using the YouTube API asp.net

查看:174
本文介绍了如何禁止使用YouTube API asp.net评论和评级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何帮助将是非常美联社preciated!

目前的code:

  YouTubeRequest请求=连接();
视频视频=新视频();

video.Tags.Add(新MediaCategory(非营利,YouTubeNameTable.CategorySchema));
video.Keywords =测试;
video.YouTubeEntry.setYouTubeExtension(位置,英国);
 

解决方案

下面的方法需要在YouTube视频从YouTube的请求服务检索并也需要在许可的类型和新的权限。

 私人视频SetAccessControl(视频录像,字符串类型,字符串许可)
    {
        VAR EXTS = video.YouTubeEntry
            .ExtensionElements
            。凡(X => x是XmlExtension)
            。选择(X => x作为XmlExtension)
            。凡(X => x.Node.Attributes [行动] = NULL和放大器;!&安培; x.Node.Attributes [行动]的InnerText ==型);

        VAR EXT = exts.FirstOrDefault();

        如果(EXT!= NULL)
            。ext.Node.Attributes [权限]的InnerText =许可;

        返回视频;
    }
 

的这个只能在一个检索到的视频,而不是如果你传递一个的新视频()

它的作用是,遍历所有你管返回作为饲料的一部分ExtentionElements,并提取XML扩展元素(因为没有一个建立在C#中的访问控制扩展)需要匹配,其中的元素动作类型==然后更新权限归因于所需的值。

当视频条目被发送和更新,以YouTube的服务器更新的访问控制元件被发回,并与更新请求。

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

解决方案

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.

这篇关于如何禁止使用YouTube API asp.net评论和评级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆