创建Azure功能“找不到作业功能"的问题;错误 [英] Issue with creating an Azure Function "No job functions found" error

查看:92
本文介绍了创建Azure功能“找不到作业功能"的问题;错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现的目标是,我希望能够创建一个Azure函数,该函数将使用YouTube API将视频上传到YouTube.示例: https://developers.google.com/youtube/v3/docs/视频/插入.创建azure函数之后,然后我想在Azure逻辑应用程序中使用该函数.这是Azure函数的代码(视频):

What I am trying to achieve is that, I want to be able to create an Azure Function that would upload a video to YouTube using the YouTube API. example:https://developers.google.com/youtube/v3/docs/videos/insert . After creating the azure function, I then want to use that function inside my Azure logic app. Here is the code for the Azure function(uploded video):

using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Upload;
using Google.Apis.Util.Store;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;


namespace Google.Apis.YouTube.Samples
    {
        /// <summary>
        /// YouTube Data API v3 sample: upload a video.
        /// Relies on the Google APIs Client Library for .NET, v1.7.0 or higher.
        /// See https://developers.google.com/api-client-library/dotnet/get_started
        /// </summary>
        public class UploadVideo
        {
            [STAThread]
            static void Main(string[] args)
            {
                Console.WriteLine("YouTube Data API: Upload Video");
                Console.WriteLine("==============================");

                try
                {
                    new UploadVideo().Run().Wait();
                }
                catch (AggregateException ex)
                {
                    foreach (var e in ex.InnerExceptions)
                    {
                        Console.WriteLine("Error: " + e.Message);
                    }
                }

                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }

            private async Task Run()
            {
                UserCredential credential;
                using (var stream = new FileStream("client_secrets.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 = "Default Video Title";
                video.Snippet.Description = "Default Video Description";
                video.Snippet.Tags = new string[] { "tag1", "tag2" };
                video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list
                video.Status = new VideoStatus();
                video.Status.PrivacyStatus = "unlisted"; // or "private" or "public"
                var filePath = @"/Users/sean/Desktop/audio/test1.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);
            }
        }
    }

运行此代码时,没有看到这样的预期结果: https://developers.google.com/youtube/v3/docs/videos#resource .相反,我遇到了错误:

When I run this code, I am not seeing the expected outcome like this: https://developers.google.com/youtube/v3/docs/videos#resource . Instead, I am getting an error :

未找到工作功能.尝试公开您的工作类别和方法.如果使用绑定扩展(例如Azure存储,ServiceBus,Timer等),请确保已在启动代码中调用了扩展的注册方法(例如builder.AddAzureStorage(),builder.AddServiceBus( ),builder.AddTimers()等).

No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

我已经公开了所有方法.我不确定我缺少什么.

I have made all my methods public. I am not sure what I am missing.

推荐答案

当您尝试创建Azure函数时,似乎使用了错误的模板,因此它创建了控制台应用程序.现在,您缺少特定于Azure函数的Nuget程序包,而且我认为您的项目还缺少某些特定于Azure函数的文件,例如host.json.

It looks like the wrong template was used when you tried to create an Azure Function, so it created a Console App instead. Right now you're missing Azure Functions specific Nuget packages and I think your project also lacks some Azure Function specific files such as the host.json.

在使用Visual Studio时,您可以尝试按照以下说明进行操作吗: https://docs.microsoft.com/zh-CN/azure/azure-functions/functions-create-your-first-function-visual-studio

Can you try following these instructions when using Visual Studio: https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-your-first-function-visual-studio

或使用VS Code时的以下说明:

Or these instructions when using VS Code: https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-vs-code?pivots=programming-language-csharp

这样,您将获得功能应用程序的正确结构,包括正确的依赖项.

This way you'll end up with a proper structure of a Function App, including the correct dependencies.

这篇关于创建Azure功能“找不到作业功能"的问题;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆