简体   繁体   English

无法访问 Dialogflow V2 检测意图 C# Webhook

[英]Unable to access Dialogflow V2 detect Intent C# Webhook

Getting following error:得到以下错误:

System.InvalidOperationException: 'The Application Default Credentials are not available. System.InvalidOperationException: '应用程序默认凭据不可用。 They are available if running in Google Compute Engine.如果在 Google Compute Engine 中运行,它们就可用。 Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials...否则,必须定义环境变量 GOOGLE_APPLICATION_CREDENTIALS 指向定义凭据的文件...

public static int DetectIntentFromTexts(string projectId,
                                        string sessionId,
                                        string text,
                                        string languageCode = "en-US")
        {

            var client = SessionsClient.Create();

            var response = client.DetectIntent(
                session: SessionName.FromProjectSession(projectId, sessionId),
                queryInput: new QueryInput()
                {
                    Text = new TextInput()
                    {
                        Text = text,
                        LanguageCode = languageCode
                    }
                });

            var queryResult = response.QueryResult;

            Console.WriteLine($"Query text: {queryResult.QueryText}");
            if (queryResult.Intent != null)
            {
                Console.WriteLine($"Intent detected: {queryResult.Intent.DisplayName}");
            }
            Console.WriteLine($"Intent confidence: {queryResult.IntentDetectionConfidence}");
            Console.WriteLine($"Fulfillment text: {queryResult.FulfillmentText}");
            Console.WriteLine();

            return 0;
        }

You need to place the Credentials.json key generated from Google cloud in your code and set it to the environment variable in the start up of your project.您需要将 Google Cloud 生成的 Credentials.json 密钥放入您的代码中,并在项目启动时将其设置为环境变量。

Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", file);

//In Global.asax.cs in case of .net framework Application //In startup.cs in case of .net core Application //In the above code line file means the local path of your credentails.json key //在Global.asax.cs的情况下.net framework Application //在startup.cs的情况下.net core Application //在上面的代码行文件中表示您的credentails.json密钥的本地路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM