c# - 无法访问 Dialogflow V2 检测 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 云生成的 Credentials.json 密钥放入您的代码中,并在项目启动时将其设置为环境变量。
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", file);
//在.net framework Application的情况下在Global.asax.cs中 //在.net core Application的情况下在startup.cs中 //在上面的代码行文件中表示您的credentails.json键的本地路径
推荐阅读
- elasticsearch - 如何将索引策略自动应用于 AWS Elasticsearch 中新创建的索引
- python - 将数据从一个 Excel 复制到另一个 Excel
- google-cloud-platform - CORS 标头存在于 PUT 请求中,但不存在于 OPTIONS 请求中
- c# - c# 三维数组变成3个一维数组
- c++ - 是否有类似于命名管道的标准 IPC 技术,无需客户端连接?
- azure - 我需要使用用户身份验证连接到 Azure 媒体服务
- r - 在 R 中合并列表的子列表
- laravel - 如何在 Laravel Eloquent 中将映射记录作为逗号分隔值获取
- r - 如何求解R中的二次方程?
- javascript - 获取星期输入的日期