【问题标题】:Using Youtube .net API to upload and set a video as unlisted使用 Youtube .net API 上传视频并将其设置为不公开
【发布时间】:2011-06-23 08:43:33
【问题描述】:

.net 的 Youtube API 似乎有一段时间没有更新了。因此,没有任何属性或方法可以将视频设置为不公开。如果他们以前遇到过这个问题,有人可以建议解决方法吗?

【问题讨论】:

标签: c# .net youtube


【解决方案1】:

这篇文章对我帮助很大:

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

我最终不得不修改代码来为属性列表添加一个空检查:

private Video SetAcessControl(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 != 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;

        return video;
    }

然后,使用它:

        YouTubeRequest request = CreateYouTubeRequest(configuration);
        Uri youTubeUrl = new Uri(string.Format("http://gdata.youtube.com/feeds/api/users/default/uploads/{0}", youTubeVideoId));
        Video video = request.Retrieve<Video>(youTubeUrl);

        video = SetAcessControl(video, "list", "denied");  // removes the video from searches, thus making it Unlisted (what you're looking for)
        video = SetAcessControl(video, "comment", "denied");  // disables comments
        video = SetAcessControl(video, "commentVote", "denied"); // disables voting on comments
        video = SetAcessControl(video, "videoRespond", "denied"); // disables video responses
        video = SetAcessControl(video, "rate", "denied"); // disables rating

        Video updatedVideo = request.Update(video);

请务必注意,这不能应用于您正在上传的视频(即您不能在调用 request.Upload(video) 之前将其应用于 new Video()。您需要等到之后在此代码生效之前,上传过程已完成。

要查看可以使用此方法禁用的项目的完整列表,请参阅以下网址: http://code.google.com/apis/youtube/2.0/reference.html#youtube_data_api_tag_yt:accessControl

希望这会有所帮助!

【讨论】:

【解决方案2】:

我也无法弄清楚这一点,所以我想我会将我的发现发布给任何寻找答案的人。

根据 this thread,在 rev 中添加了对 yt:accessControl 的支持。 1118.

在撰写本文时,该修订版并未包含在您从 Google 的 API 下载页面下载的 API 中。您必须获得最新版本的 API here (SVN Checkout)。

一旦你有了它,你可以做这样的事情:

Video newVideo = new Video();
newVideo.YouTubeEntry.AccessControls.Add(new YtAccessControl("list", "denied"));

干杯!

【讨论】:

  • 现在在官方可下载的 API 中。
【解决方案3】:

使用您的“YouTubeRequestSettings”传递用户名和密码。

例子

YouTubeRequestSettings settings = new YouTubeRequestSettings("My Channel", YouTubeDeveloperKey, "username", "password");

如果您想检索“不公开”或“私人”视频,您需要通过身份验证。

【讨论】:

    猜你喜欢
    • 2011-10-09
    • 2023-04-03
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 2013-10-08
    • 2017-08-02
    • 2013-03-27
    • 1970-01-01
    相关资源
    最近更新 更多