【问题标题】:Raw File is always "unknown" when uploaded through Youtube API v3通过 Youtube API v3 上传时,原始文件总是“未知”
【发布时间】:2018-05-01 05:38:25
【问题描述】:

任何使用 .Net Youtube API v3 C# 上传的视频,在您检查上传文件(Raw 文件)的原始文件名时,始终被视为“未知”。

我搜索了很多,可以找到一些相同的问题但没有解决方案,所以我不知道是否每个人都得到了它,这并不是什么大事,或者人们是否知道解决方案。

上传的代码是原始示例代码(我尝试修改东西以了解是否有用)。

        async void Upload()
    {
        _lastBytes = 0;
        _currentItem = -1;
        for (_currentItem = 0; _currentItem < WorkList.Count; _currentItem++)
        {
            var videoSource = WorkList[_currentItem];
            UserCredential credential;
            using (var stream = new FileStream("YourJsonFile", FileMode.Open, FileAccess.Read))
            {
                credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    // This OAuth 2.0 access scope allows an application to upload files to the
                    // authenticated user's YouTube channel, but doesn't allow other types of access.
                    new[] { YouTubeService.Scope.YoutubeUpload },
                    "user",
                    CancellationToken.None
                    );
            }
            var youtubeService = new YouTubeService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
            });

            var video = new Video();
            video.Snippet = new VideoSnippet();
            video.Snippet.Title = videoSource.Title;
            if (videoSource.Description != null)
                video.Snippet.Description = videoSource.Description;
            if (videoSource.Tags != null)
                video.Snippet.Tags = videoSource.Tags.Split(',');
            video.Snippet.CategoryId = "22";
            // See https://developers.google.com/youtube/v3/docs/videoCategories/list
            video.Status = new VideoStatus();
            video.Status.PrivacyStatus = "private"; // or "private" or "public"
            var filePath = videoSource.Path; // Replace with path to actual movie file.

            using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                _size = fileStream.Length;

                var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status,contentDetails",
                    fileStream, "video/*");
                videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
                videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
                await videosInsertRequest.UploadAsync();
            }
        }
    }

该代码与示例代码相同,只是我有一个用于获取视频的 for 循环。

不知道是不是只有C#才有这个问题,还是我只是瞎了眼,解决方法很明显。

为了以防万一,我在他们的错误跟踪器上发布了一个问题:https://code.google.com/p/gdata-issues/issues/detail?id=7140&can=6&sort=-id&colspec=API%20ID%20Type%20Status%20Priority%20Stars%20Summary

谢谢。

【问题讨论】:

  • 您找到解决方案了吗?

标签: c# youtube-api


【解决方案1】:

要设置 RAW 文件名,请添加到 HTTP 侦听器:

"Slug:"+ 你的文件名。

我不使用谷歌库,所以我不知道如何使用 .Net Youtube API v3 C# 进行设置

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 1970-01-01
    • 2015-07-25
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多