当您查看上传文件(原始文件)的原始文件名时,任何使用.Net Youtube API v3 C#上传的视频都会被认为是“未知”。
我已经搜索了很多,可以找到一些同样的问题,但没有解决方案,所以我不知道是否每个人都得到了它,这只是一个不大的事情,或者如果人们知道解决方案。
用于上传的代码是原始示例代码(我尝试修改内容以了解其有效性)。
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
谢谢。
发布于 2015-10-16 16:27:53
要设置原始文件名,请添加到HTTP Hearder:
"Slug:"+你的文件名。
我不使用google库,所以我不知道如何使用.Net Youtube API v3 C#进行设置。
https://stackoverflow.com/questions/30113363
复制相似问题