gpt4 book ai didi

c# - 用于上传视频的YouTube数据API在MVC中不起作用

转载 作者:行者123 更新时间:2023-12-03 05:56:55 26 4
gpt4 key购买 nike

我正尝试使用YouTube数据API从我的应用程序将视频上​​传到YouTube,但很遗憾,YouTube开发人员提供了该API

https://developers.google.com/youtube/v3/code_samples/dotnet#upload_a_video



在三周前我无法测试代码,但仍能正常工作,但是现在当我尝试在应用程序中最终使用它时,会导致所有代码正常工作,但是当视频上传过程开始时,它已开始加载和加载,该视频未在Google上载,但未找到任何帮助。是否有人可以帮助我?这是我正在使用的代码
 private async Task Run()
{
UserCredential credential;
using (var stream = new FileStream("G:\\client_secret_783534382593-0cn4gm229raqq97kdu0ghsj9hqfsc5o1.apps.googleusercontent.com.json", 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 = "ttry";
video.Snippet.Description = " Video Description";
video.Snippet.Tags = new string[] { "tag1s", "tag2s" };
video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "public"; // or "private" or "publi
var filePath = "F:\\Dna.MP4"; // Replace with path to actual movie file.

using (var fileStream = new FileStream(filePath, FileMode.Open))
{
var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;

await videosInsertRequest.UploadAsync();
}
}

void videosInsertRequest_ProgressChanged(Google.Apis.Upload.IUploadProgress progress)
{
switch (progress.Status)
{
case UploadStatus.Uploading:
Console.WriteLine("{0} bytes sent.", progress.BytesSent);
break;

case UploadStatus.Failed:
Console.WriteLine("An error prevented the upload from completing.\n{0}", progress.Exception);
break;
}
}

void videosInsertRequest_ResponseReceived(Video video)
{
Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id);
}
}
}

我只是从这个 Action 中称呼它
  public ActionResult Contact()
{
Run().Wait();

return View();
}

我不知道为什么它不起作用?当我调试它时,所有东西和参数都很好,即使凭据也很好,但是最后,即使我选择1 MB文件,文件也没有上传,我还包括了所有必要的NuGet软件包,请有人帮我?

最佳答案

问题是通过简单地在Get Function中添加一些代码来解决的

public async Task<ActionResult> Contact()
{
await Run();
return View();
}

关于c# - 用于上传视频的YouTube数据API在MVC中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36162229/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com