【问题标题】:Disabling Comments - Video's ResponseURI is System.NullReferenceException禁用评论 - 视频的 ResponseURI 是 System.NullReferenceException
【发布时间】:2014-07-02 17:16:06
【问题描述】:

因为 Youtube Data Api v3 还不允许为视频禁用 cmets...我正在尝试使用 Youtube Data API v2 检索视频,更新其设置以禁用 cmets 并将其上传回来。

几天前我能够做到这一点,但我不确定为什么现在无法正常工作。我遇到的一件事是当我检索视频时,我可以更新设置,当我将其上传回来时,我得到一个空引用异常。奇怪。

看起来视频的 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)
        {
        }


    }

如果能帮助您了解如何更新此视频,我们将不胜感激 - 谢谢!

【问题讨论】:

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


    【解决方案1】:

    显然,截至 3 月 4 日,视频响应已被禁用,这在几周前还有效,但贬值一定是禁用了 ResponseURI。

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

    【讨论】:

    • 您可以使用channels资源更新方法,该方法可以让您使用brandingSettings.channel.moderateComments。
    • 感谢 hipokito - 但我认为这只允许 cmets 的节制,而不是 cmets 的禁用。我需要能够根本不允许 cmets
    • 属性描述说明:此设置决定了用户提交的留在频道页面上的cmets是否需要频道所有者批准才能公开可见。默认值为假。如果这不是禁用 cmets,那么是什么?你的意思是,删除输入字段?如果是这样,我相信这是不可能的。
    • Issue 473 要求将禁用 cmets 的功能添加到 API V3。点击星号表示您同意该请求并获取最新状态。
    • 我尝试设置 brandingSettings.channel.moderateComments 属性,但得到“访问冲突”。程序“XXX.exe”已退出,代码为 -1073741819 (0xc0000005)“访问冲突”。
    猜你喜欢
    • 1970-01-01
    • 2012-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 2013-11-21
    • 2016-07-21
    • 1970-01-01
    相关资源
    最近更新 更多