首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >原始文件在通过Youtube API v3上传时总是“未知”的

原始文件在通过Youtube API v3上传时总是“未知”的
EN

Stack Overflow用户
提问于 2015-05-08 07:31:38
回答 1查看 652关注 0票数 0

当您查看上传文件(原始文件)的原始文件名时,任何使用.Net Youtube API v3 C#上传的视频都会被认为是“未知”。

我已经搜索了很多,可以找到一些同样的问题,但没有解决方案,所以我不知道是否每个人都得到了它,这只是一个不大的事情,或者如果人们知道解决方案。

用于上传的代码是原始示例代码(我尝试修改内容以了解其有效性)。

代码语言:javascript
运行
复制
        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#上,或者我只是盲目的,解决方案很明显。

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

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2015-10-16 16:27:53

要设置原始文件名,请添加到HTTP Hearder:

"Slug:"+你的文件名。

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30113363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档