禁用评论 - 视频的ResponseURI是System.NullReferenceException

时间:2014-05-14 14:55:21

标签: c# youtube-api youtube-data-api

因为Youtube Data Api v3不允许停用视频评论...我正在尝试使用Youtube Data 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)
        {
        }


    }

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

1 个答案:

答案 0 :(得分:0)

显然,视频回复已于3月4日停用,这在几周前已经停止,但是这种处理必须禁用ResponseURI。

任何人都知道如何在v3 youtube api中停用视频评论?