Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法成功运行Azure函数,该函数包含将视频上载到YouTube的代码_C#_.net Core_Azure Functions_Youtube Data Api_Google Api Dotnet Client - Fatal编程技术网

C# 无法成功运行Azure函数,该函数包含将视频上载到YouTube的代码

C# 无法成功运行Azure函数,该函数包含将视频上载到YouTube的代码,c#,.net-core,azure-functions,youtube-data-api,google-api-dotnet-client,C#,.net Core,Azure Functions,Youtube Data Api,Google Api Dotnet Client,我基本上是在创建一个HTTP Trigger Azure函数,该函数包含使用YouTube API将视频上传到YouTube的代码。代码基本上是由YouTubeAPI文档提供的:。我重新格式化了代码,使之适合Azure函数 但是,当我尝试在Visual Studio上本地运行该函数时,会出现一个500错误,错误是: 执行“功能1”(失败,Id=84400f0c-b6e4-4c78-bf55-30c4527a8b5f) System.Private.CoreLib:执行函数Function1时发生

我基本上是在创建一个HTTP Trigger Azure函数,该函数包含使用YouTube API将视频上传到YouTube的代码。代码基本上是由YouTubeAPI文档提供的:。我重新格式化了代码,使之适合Azure函数

但是,当我尝试在Visual Studio上本地运行该函数时,会出现一个500错误,错误是:

执行“功能1”(失败,Id=84400f0c-b6e4-4c78-bf55-30c4527a8b5f) System.Private.CoreLib:执行函数Function1时发生异常。 System.Private.CoreLib:找不到文件 'C:\Users\Peter\Desktop\TestDemo\UploadVideo\UploadVideo\bin\Debug\netcoreapp2.1\client\u secrets.json'

我不知道如何修复此错误,并使函数在没有任何错误的情况下运行。是否需要在代码(以下)中添加/更改任何内容来修复此问题

我的目标:我的最终目标是在azure Blob存储中添加新视频时触发此azure功能

代码

使用系统;
使用System.IO;
使用System.Threading.Tasks;
使用Microsoft.AspNetCore.Mvc;
使用Microsoft.Azure.WebJobs;
使用Microsoft.Azure.WebJobs.Extensions.Http;
使用Microsoft.AspNetCore.Http;
使用Microsoft.Extensions.Logging;
使用Newtonsoft.Json;
使用Google.api.Auth.OAuth2;
使用Google.api.Upload;
使用Google.api.YouTube.v3.Data;
运用系统反思;
使用Google.api.YouTube.v3;
使用Google.api.Services;
使用系统线程;
命名空间上载视频
{
公共静态类函数1
{
[功能名称(“功能1”)]
公共静态异步任务运行(
[HttpTrigger(AuthorizationLevel.Function,“get”,“post”,Route=null)]HttpRequest请求,
ILogger日志)
{
LogInformation(“C#HTTP触发器函数处理了一个请求。”);
登录信息(“YouTube数据API:上传视频”);
日志。登录信息(“====================================================”);
尝试
{
等待运行();
}
捕获(聚合异常)
{
foreach(ex.InnerExceptions中的变量e)
{
登录信息(“错误:+e.Message”);
}
}
返回新的OkObjectResult($“视频处理…”);
}
专用静态异步任务运行()
{
用户凭证;
使用(var stream=newfilestream(“client_secrets.json”、FileMode.Open、FileAccess.Read))
{
凭证=等待GoogleWebAuthorizationBroker.AuthorizationAsync(
GoogleClientSecrets.Load(stream.Secrets),
//此OAuth 2.0访问范围允许应用程序将文件上载到
//已验证用户的YouTube频道,但不允许其他类型的访问。
新[]{YouTubeService.Scope.YoutubeUpload},
“用户”,
取消令牌。无
);
}
var youtubeService=new youtubeService(new BaseClientService.Initializer()
{
HttpClientInitializer=凭证,
ApplicationName=Assembly.GetExecutionGassembly().GetName().Name
});
var video=新视频();
video.Snippet=新的VideoSnippet();
video.Snippet.Title=“默认视频标题”;
video.Snippet.Description=“默认视频描述”;
video.Snippet.Tags=新字符串[]{“tag1”、“tag2”};
video.Snippet.CategoryId=“22”//请参阅https://developers.google.com/youtube/v3/docs/videoCategories/list
video.Status=新的VideoStatus();
video.Status.PrivacyStatus=“未列出”;//或“私有”或“公共”
var filePath=@“C:\Users\Peter\Desktop\audio\test.mp4”//替换为实际电影文件的路径。
使用(var fileStream=newfilestream(filePath,FileMode.Open))
{
var videosInsertRequest=youtubeService.Videos.Insert(视频,“片段,状态”,文件流,“视频/*”;
videosInsertRequest.ProgressChanged+=videosInsertRequest\u ProgressChanged;
videosInsertRequest.ResponseReceived+=videosInsertRequest_ResponseReceived;
等待videosInsertRequest.UploadAsync();
}
}
私有静态void videosInsertRequest_ProgressChanged(Google.api.Upload.IUploadProgress)
{
开关(进度状态)
{
案例上传状态。上传:
WriteLine(“{0}字节已发送。”,progress.BytesSent);
打破
案例上载状态。失败:
WriteLine(“一个错误阻止上载完成。\n{0}”,progress.Exception);
打破
}
}
私有静态无效视频接收请求_响应(视频)
{
WriteLine(“视频id{0}已成功上载。”,Video.id);
}
}
}
找不到文件“C:\Users\Peter\Desktop\TestDemo\UploadVideo\UploadVideo\bin\Debug\netcoreapp2.1\client\u secrets.json”

它在寻找“client_secrets.json”,它需要与代码位于同一目录中。因为你没有告诉它去别的地方看看

using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
        {
注 GoogleWebAuthorizationBroker.AuthorizationAsync仅设计用于安装的应用程序,它将在服务器上打开web浏览器并提示用户验证代码

如果im错误,请更正我,但是azure函数没有可以提示用户进行身份验证的ui端点。这意味着你只能使用一个服务帐户,而YouTube api不支持该服务 账目

找不到文件“C:\Users\Peter\Deskto”
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
        {