Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 禁用评论-视频';s ResponseURI是System.NullReferenceException_C#_Youtube Api_Youtube Data Api - Fatal编程技术网

C# 禁用评论-视频';s ResponseURI是System.NullReferenceException

C# 禁用评论-视频';s ResponseURI是System.NullReferenceException,c#,youtube-api,youtube-data-api,C#,Youtube Api,Youtube Data Api,因为Youtube数据Api v3还不允许禁用视频评论。。。我正在尝试使用Youtube数据API v2检索视频,更新其设置以禁用评论并将其上载回 几天前我就能够做到这一点,我不知道为什么现在一切都不顺利。我遇到的一件事是,当我检索视频时,我可以更新设置,当我上传回来时,我得到一个空引用异常。奇怪 看起来视频的responseURI将作为system.SystemNullReference异常返回 以下是我正在使用的代码: private void DisableComments(str

因为Youtube数据Api v3还不允许禁用视频评论。。。我正在尝试使用Youtube数据API v2检索视频,更新其设置以禁用评论并将其上载回

几天前我就能够做到这一点,我不知道为什么现在一切都不顺利。我遇到的一件事是,当我检索视频时,我可以更新设置,当我上传回来时,我得到一个空引用异常。奇怪

看起来视频的responseURI将作为system.SystemNullReference异常返回

以下是我正在使用的代码:

    private void DisableComments(string videoId)
    {

        Google.YouTube.Video ourVideoToUpdate = SetAcessControl( channelId, videoId, "comment", "denied");
        UpdateVideoSettings( ourVideoToUpdate);

    }

    private Google.YouTube.Video SetAcessControl(string channelId, string videoId, string type, string permission)
    {

        Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/users/" + channelId + "/uploads/" + videoId);

        Google.YouTube.YouTubeRequestSettings settings = new Google.YouTube.YouTubeRequestSettings("VideoGenerator", DeveloperKeyHere, UsernameHere, PasswordHere);

        Google.YouTube.YouTubeRequest ourRequest = new Google.YouTube.YouTubeRequest(settings);

        Google.YouTube.Video videoToAdjust = new Google.YouTube.Video();
        try
        {


             Google.YouTube.Video video = ourRequest.Retrieve<Google.YouTube.Video>(videoEntryUrl);


            var exts = videoToAdjust.YouTubeEntry.ExtensionElements
                      .Where(x => x is Google.GData.Extensions.XmlExtension)
                      .Select(x => x as Google.GData.Extensions.XmlExtension)
                      .Where(x => x.Node.Attributes != null && x.Node.Attributes["action"] != null && x.Node.Attributes["action"].InnerText == type);


            var ext = exts.FirstOrDefault();

            if (ext != null) ext.Node.Attributes["permission"].InnerText = permission;
         }
         catch (Google.GData.Client.GDataRequestException ex)
        {
            videoToAdjust = null;
        }

        return videoToAdjust;

    }

    private void UpdateVideoSettings(Google.YouTube.Video videoToUpdate)
    {
        Google.YouTube.YouTubeRequestSettings settings = new Google.YouTube.YouTubeRequestSettings("VideoGenerator", DeveloperKeyHere, UsernameHere, passwordHere);
        Google.YouTube.YouTubeRequest ourUpdateRequest = new Google.YouTube.YouTubeRequest(settings);

        try
        {
            // NULL REFERENCE EXCEPTION HERE - cant upload
            ourUpdateRequest.Update<Google.YouTube.Video>(videoToUpdate);
        }

        catch (Exception ex)
        {
        }


    }
private void DisableComments(字符串videoId)
{
Google.YouTube.Video ourVideoToUpdate=setacescontrol(channelId,videoId,“评论”,“拒绝”);
更新视频设置(我们的视频更新);
}
私有Google.YouTube.Video setAcesControl(字符串通道ID、字符串视频ID、字符串类型、字符串权限)
{
Uri videoEntryUrl=新Uri(“http://gdata.youtube.com/feeds/api/users/“+channelId+”/上传/“+videoId);
Google.YouTube.youtuberrequestsettings=new Google.YouTube.youtuberrequestsettings(“视频生成器”,DeveloperKeyHere,UsernameHere,PasswordHere);
Google.YouTube.YouTubeRequest-ourRequest=新建Google.YouTube.YouTubeRequest(设置);
Google.YouTube.Video videoToAdjust=新的Google.YouTube.Video();
尝试
{
Google.YouTube.Video Video=ourRequest.Retrieve(videoEntryUrl);
var exts=videoToAdjust.YouTubeEntry.ExtensionElements
.Where(x=>x是Google.GData.Extensions.XmlExtension)
.Select(x=>x为Google.GData.Extensions.XmlExtension)
.Where(x=>x.Node.Attributes!=null&&x.Node.Attributes[“操作”!=null&&x.Node.Attributes[“操作”]。InnerText==type);
var ext=exts.FirstOrDefault();
如果(ext!=null)ext.Node.Attributes[“权限”]。InnerText=权限;
}
catch(Google.GData.Client.GDataRequestException ex)
{
videoToAdjust=null;
}
重新调整;
}
私有void更新视频设置(Google.YouTube.Video-videoToUpdate)
{
Google.YouTube.youtuberrequestsettings=new Google.YouTube.youtuberrequestsettings(“视频生成器”,DeveloperKeyHere,UsernameHere,passwordHere);
Google.YouTube.YouTubeRequest-ourUpdateRequest=新建Google.YouTube.YouTubeRequest(设置);
尝试
{
//此处出现空引用异常-无法上载
更新(videoToUpdate);
}
捕获(例外情况除外)
{
}
}

任何帮助了解如何更新此视频将不胜感激-谢谢

显然,从3月4日起,视频响应已被禁用,这在几周前还可以正常工作,但解除润滑必须已禁用响应


有人知道如何在v3 youtube api中禁用视频评论吗?

您可以使用资源更新方法,该方法允许您使用brandingSettings.channel.moderateComments.Thank hipokito-但我认为这只允许评论的缓和,而不允许禁用评论。我需要能够在所有属性描述状态下不允许评论:此设置确定用户提交的保留在频道页面上的评论是否需要得到频道所有者的批准才能公开可见。默认值为false。如果这不是禁用注释,那么什么是禁用注释?你是说删除输入字段?如果是这样,我相信这是不可能的。要求提供禁用要添加到API V3的注释的功能。单击星号表示您同意请求并获取状态更新。我尝试设置brandingSettings.channel.moderateComments属性,但获得“访问冲突”。程序“XXX.exe”已退出,代码为-1073741819(0xc0000005)“访问冲突”。