YouTube C#API V3,如何删除不带ID的部分上传的视频? [英] YouTube C# API V3, how do you delete a partially uploaded video without the ID?

查看:74
本文介绍了YouTube C#API V3,如何删除不带ID的部分上传的视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ResponseReceived事件中返回了VideoID,但未在上传完成之前返回.如果用户取消并删除了上载,如何将其从YouTube服务器上删除?

The VideoID is returned in the ResponseReceived event but not before the upload has completed. If the user cancels and deletes the upload, how do you delete it from the YouTube servers?

我目前正在做的是一个丑陋但可以正常工作的黑客程序.

What I'm currently doing is an ugly but working hack.

我将标题设置为唯一的GUID.上传完成后,我设置了正确的标题.

I set the title to a unique guid. When the upload completes, I set the correct title.

如果上传被删除,我将获得第一个频道,并在播放列表中搜索GUID标题.这将返回VideoID,我可以删除视频.

If the upload is deleted, I get the first channel and search the playlist for the guid title. This returns the VideoID and I can delete the video.

必须有更好的方法.我可以使用响应中的upload_id吗?

There has to be a better way. Can I use the upload_id from the response?

推荐答案

除非有人提出了一个更好的主意,否则这是我目前正在做的事情,并且似乎运行得很好.一个警告是,如果视频恰好具有相同的guid标签,它们可能会消失,但我认为这不太可能.

Unless someone comes up with a better idea, this is what I'm currently doing and it appears to be working quite well. One caveat is the potential for videos to disappear if they happen to have the same guid tag but I don't think that's very likely.

使用了一些常量字符串

internal const string PartSnippet = "snippet";
internal const string TypeVideo = "video";

在开始上传之前,我会添加一个guid标签.

Before I kick off the upload, I add a guid tag.

video.Snippet.Tags.Add(upload.UploadId.ToString());

在ResponseReceived事件中,上传完成后,我删除了标签

In the ResponseReceived event, when the upload completes, I remove the tag

YouTube.RemoveTag(obj, Upload.UploadId.ToString());

internal static void RemoveTag(Video video, string tag)
{           
    video.Snippet.Tags.Remove(tag);
    var updateRequest = YouTubeService.Videos.Update(video, Constants.PartSnippet);
    updateRequest.ExecuteAsync();
}

如果需要将视频从服务器中删除,我将通过guid标签对其进行搜索并将其删除.

If the video needs to be removed from the server, I search for it by guid tag and delete it.

YouTube.DeleteAsyncVideoByGuidTag(Upload.UploadId);

internal async static Task DeleteAsyncVideoByGuidTag(Guid tag)
{
    var listRequest = YouTubeService.Search.List(Constants.PartSnippet);
    listRequest.ForMine = true;
    listRequest.Type = Constants.TypeVideo;
    listRequest.Q = tag.ToString();
    var response = await listRequest.ExecuteAsync();
    foreach (var deleteRequest in response.Items.Select(
        result => YouTubeService.Videos.Delete(result.Id.VideoId)))             
        await deleteRequest.ExecuteAsync();
}

请注意:这是一种解决方法.这不是我想要的方法,但这是我想到的唯一方法.

Please note: This is a workaround. It's not the way I'd like to do it but it's the only way I can think of doing it.

这篇关于YouTube C#API V3,如何删除不带ID的部分上传的视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆