我想使用 API 从我的 Youtube 频道中删除视频

发布于 2024-12-24 02:50:58 字数 859 浏览 4 评论 0原文

这是我的代码:

YouTubeService serv = new YouTubeService("myDeleteService", YOUTUBE_DEVELOPER_KEY);            
serv.setUserCredentials(USERNAME, PASSWORD);
YouTubeRequestSettings settings = new YouTubeRequestSettings(YOUTUBE_CHANNEL, YOUTUBE_DEVELOPER_KEY);
YouTubeRequest request = new YouTubeRequest(settings);
string feedUrl = String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads", YOUTUBE_CHANNEL);
Feed<Video> videoFeed = request.Get<Video>(new Uri(feedUrl));
Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + VideoId);
Video video = request.Retrieve<Video>(videoEntryUrl);
Video vid = (from vi in videoFeed.Entries
             where vi.VideoId == VideoId
             select vi).First<Google.YouTube.Video>();
request.Delete(vid);

代码在最后一行中断,说明对象引用未设置为对象。

This is my code:

YouTubeService serv = new YouTubeService("myDeleteService", YOUTUBE_DEVELOPER_KEY);            
serv.setUserCredentials(USERNAME, PASSWORD);
YouTubeRequestSettings settings = new YouTubeRequestSettings(YOUTUBE_CHANNEL, YOUTUBE_DEVELOPER_KEY);
YouTubeRequest request = new YouTubeRequest(settings);
string feedUrl = String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads", YOUTUBE_CHANNEL);
Feed<Video> videoFeed = request.Get<Video>(new Uri(feedUrl));
Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + VideoId);
Video video = request.Retrieve<Video>(videoEntryUrl);
Video vid = (from vi in videoFeed.Entries
             where vi.VideoId == VideoId
             select vi).First<Google.YouTube.Video>();
request.Delete(vid);

The code breaks on the last line stating that object reference is not set to an object.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

软的没边 2024-12-31 02:50:58

这似乎是 Google YouTube API 内部的问题。我对良好的请求和视频对象也有同样的问题。 (Google API v1.9.0.0)

更新:查看下面 Claudio 的回复。这是正确的。我收到了支持人员回复的电子邮件,但忘记更新此答案:

此 uri 将失败:
“http://gdata.youtube.com/feeds/api/videos/” + videoID

这将起作用:
“http://gdata.youtube.com/feeds/api/users/”+ 帐户名+“/uploads/”+ 视频ID

This appears to be an issue internal to the Google YouTube API. I'm having the same issue with good request and video objects. (Google API v1.9.0.0)

UPDATE: check out Claudio's response below. It is correct. I received an email back from support and forgot to update this answer:

this uri will fail:
"http://gdata.youtube.com/feeds/api/videos/" + videoID

this will work:
"http://gdata.youtube.com/feeds/api/users/" + accountName + "/uploads/" + videoID

神爱温柔 2024-12-31 02:50:58

如果您使用正确的 url(即 /upload feed 中的 url),Delete 方法将按预期工作。

/videos feed 中的条目没有编辑 URL,而发送删除请求必须使用该编辑 URL。我刚刚更新了库(修订版 1169)以返回更有意义的 ArgumentNullException 而不是通用空引用。

请使用此代码删除您上传的视频:

YouTubeRequestSettings settings = new YouTubeRequestSettings(YOUTUBE_CHANNEL, YOUTUBE_DEVELOPER_KEY, USERNAME, PASSWORD);
YouTubeRequest request = new YouTubeRequest(settings);
Uri videoEntryUrl = new Uri(String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads/{1}", YOUTUBE_CHANNEL, VIDEO_ID));
Video video = request.Retrieve<Video>(videoEntryUrl);
request.Delete(video);

The Delete method works as expected if you use the right url, i.e. the one from the /upload feed.

The entries in the /videos feed do not have an edit url which is the one that must be used to send a delete request. I just updated the library (rev. 1169) to return a more meaningful ArgumentNullException instead of the generic null reference.

Please use this code to delete a video you uploaded:

YouTubeRequestSettings settings = new YouTubeRequestSettings(YOUTUBE_CHANNEL, YOUTUBE_DEVELOPER_KEY, USERNAME, PASSWORD);
YouTubeRequest request = new YouTubeRequest(settings);
Uri videoEntryUrl = new Uri(String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads/{1}", YOUTUBE_CHANNEL, VIDEO_ID));
Video video = request.Retrieve<Video>(videoEntryUrl);
request.Delete(video);
扎心 2024-12-31 02:50:58

我有以下内容:

CreateAuthenticatedRequest().Service.Delete(new Uri(GetVideoUploadUrl(videoId)));

    public static YouTubeRequest CreateAuthenticatedRequest()
    {
        YouTubeRequestSettings settings = new YouTubeRequestSettings(ConfigurationManager.AppSettings["GData.AppName"],  ConfigurationManager.AppSettings["GData.DeveloperKey"], ConfigurationManager.AppSettings["GData.Email"], ConfigurationManager.AppSettings["GData.Password"]);
        settings.Timeout = 1000000;
        return new YouTubeRequest(settings);
    }

    private static string GetVideoUploadUrl(string videoId)
    {
        return string.Format("http://gdata.youtube.com/feeds/api/users/default/uploads/{0}", videoId);
    }

I have the following:

CreateAuthenticatedRequest().Service.Delete(new Uri(GetVideoUploadUrl(videoId)));

    public static YouTubeRequest CreateAuthenticatedRequest()
    {
        YouTubeRequestSettings settings = new YouTubeRequestSettings(ConfigurationManager.AppSettings["GData.AppName"],  ConfigurationManager.AppSettings["GData.DeveloperKey"], ConfigurationManager.AppSettings["GData.Email"], ConfigurationManager.AppSettings["GData.Password"]);
        settings.Timeout = 1000000;
        return new YouTubeRequest(settings);
    }

    private static string GetVideoUploadUrl(string videoId)
    {
        return string.Format("http://gdata.youtube.com/feeds/api/users/default/uploads/{0}", videoId);
    }
痞味浪人 2024-12-31 02:50:58

这意味着您的 LINQ 查询可能不会返回任何内容,即 null。检查调试器中的 vid 变量,或者更好的是,添加一个 if 条件来查看 vid 是否具有有效值。

This means that your LINQ query is probably returning nothing i.e., null. Check the vid variable in debugger or better yet, put an if condition to see whether vid has a valid value or not.

他是夢罘是命 2024-12-31 02:50:58

我花了 5 个多小时尝试使用官方示例代码删除视频:

YouTubeRequestSettings settings = new YouTubeRequestSettings(YOUTUBE_CHANNEL, YOUTUBE_DEVELOPER_KEY, USERNAME, PASSWORD);
YouTubeRequest request = new YouTubeRequest(settings);
Uri videoEntryUrl = new Uri(String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads/{1}", YOUTUBE_CHANNEL, VIDEO_ID));
Video video = request.Retrieve<Video>(videoEntryUrl);
request.Delete(video);

并且我遇到了 410 状态代码的异常。我不知道为什么,但根据 ScottE 回答,此代码删除视频:

YouTubeRequestSettings settings = new YouTubeRequestSettings(YOUTUBE_CHANNEL, YOUTUBE_DEVELOPER_KEY, USERNAME, PASSWORD);
YouTubeRequest request = new YouTubeRequest(settings);
Uri uri = new Uri(String.Format("http://gdata.YouTube.com/feeds/api/users/default/uploads/{0}", videoId));
request.Service.Delete(uri);

所以我使用 request.Service.Delete(uri); 除了 request.Delete(video );

I spent over 5 hours trying to delete video with official sample code:

YouTubeRequestSettings settings = new YouTubeRequestSettings(YOUTUBE_CHANNEL, YOUTUBE_DEVELOPER_KEY, USERNAME, PASSWORD);
YouTubeRequest request = new YouTubeRequest(settings);
Uri videoEntryUrl = new Uri(String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads/{1}", YOUTUBE_CHANNEL, VIDEO_ID));
Video video = request.Retrieve<Video>(videoEntryUrl);
request.Delete(video);

and I had and exception with 410 status code. I don't know why but according ScottE answer this code deletes video:

YouTubeRequestSettings settings = new YouTubeRequestSettings(YOUTUBE_CHANNEL, YOUTUBE_DEVELOPER_KEY, USERNAME, PASSWORD);
YouTubeRequest request = new YouTubeRequest(settings);
Uri uri = new Uri(String.Format("http://gdata.YouTube.com/feeds/api/users/default/uploads/{0}", videoId));
request.Service.Delete(uri);

So I used request.Service.Delete(uri); except request.Delete(video);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文