繁体   English   中英

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

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

得到以下错误:

System.InvalidOperationException: '应用程序默认凭据不可用。 如果在 Google Compute Engine 中运行,它们就可用。 否则,必须定义环境变量 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;
        }

您需要将 Google Cloud 生成的 Credentials.json 密钥放入您的代码中,并在项目启动时将其设置为环境变量。

Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", file);

//在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